Skip to contentSkip to conversation

Add ctf_integer_bitfield_type

PATCH Superseded Julien Desfossez 2 participants 11 messages Apr 23, 2016 – Apr 29, 2016 6 messages not in the archive

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

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

#1 lore raw

PATCH v5 1/5 Add ctf_integer_bitfield_type

---
 probes/lttng-events-write.h | 8 ++++++++
 1 file changed, 8 insertions(+)
probes/lttng-events-write.h +8 -0
index 5db66eb..87741a1 100644
@@ -22,6 +22,10 @@
 #define ctf_integer(_type, _item, _src)				\
 	_ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, 0, 0)
 
+#undef ctf_integer_bitfield
+#define ctf_integer_bitfield(_type, _item, _src)			\
+	_ctf_integer_ext(_type, _item, _src, __LITTLE_ENDIAN, 10, 0, 0)
+
 #undef ctf_integer_hex
 #define ctf_integer_hex(_type, _item, _src)			\
 	_ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 16, 0, 0)
@@ -145,6 +149,10 @@
 #define ctf_integer_type(_type, _src)					\
 	ctf_integer(_type, unused, _src)
 
+#undef ctf_integer_bitfield_type
+#define ctf_integer_bitfield_type(_type, _src)				\
+	ctf_integer_bitfield(_type, unused, _src)
+
 #undef ctf_integer_hex_type
 #define ctf_integer_hex_type(_type, _src)				\
 	ctf_integer_hex(_type, unused, _src)
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#2 lore raw

PATCH v5 2/5 Extract the FD sets in select and pselect6

In reply to a message not in the archive

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 uint8_t (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 5 to 19 (0xFFFF0), it returns that one FD is ready: FD 12 (0x1000).

syscall_entry_select: {
n = 20,
_fdset_in_length = 3, fdset_in = [ [0] = 0xF0, [1] = 0xFF, [2] = 0xF ], _fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}

syscall_exit_select: {
ret = 1,
_fdset_in_length = 3, fdset_in = [ [0] = 0x0, [1] = 0x10, [2] = 0x0 ], _fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}

---
 .../syscalls/headers/syscalls_pointers_override.h  | 510 +++++++++++++++++++++
 1 file changed, 510 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +510 -0
index bf5c632..ef4dc1c 100644
@@ -53,4 +53,514 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe2,
 	)
 )
 
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
+#define OVERRIDE_32_select
+#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, *fds_out, *fds_ex;
+		unsigned long nr_bytes, nr_ulong;
+		unsigned int overflow;
+	),
+	TP_code_pre(
+		sc_inout(
+		{
+			int err;
+
+			tp_locvar->fds_in = NULL;
+			tp_locvar->fds_out = NULL;
+			tp_locvar->fds_ex = NULL;
+
+			tp_locvar->overflow = 0;
+
+			sc_out(
+				if (ret <= 0)
+					goto error;
+			)
+
+			if (n <= 0)
+				goto error;
+
+			/* Limit atomic memory allocation to one page */
+			if (DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) > PAGE_SIZE) {
+				tp_locvar->nr_bytes = PAGE_SIZE;
+				tp_locvar->nr_ulong = PAGE_SIZE / sizeof(unsigned long);
+				/* Inform the user that we did not output everything. */
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+				tp_locvar->nr_ulong = DIV_ROUND_UP((unsigned int) n,
+					BITS_PER_BYTE * sizeof(unsigned long));
+			}
+			/* On error or bogus input, don't copy anything. */
+			if (tp_locvar->nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+				goto error;
+			}
+
+			if (inp) {
+				tp_locvar->fds_in = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_in)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_in, inp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (outp) {
+				tp_locvar->fds_out = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_out)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_out, outp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (exp) {
+				tp_locvar->fds_ex = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_ex)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_ex, exp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			goto end;
+
+	error:
+		tp_locvar->nr_bytes = 0;
+		tp_locvar->nr_ulong = 0;
+	end:
+		/* bypass error: label at end of compound statement */
+		;
+		}
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+
+		sc_inout(
+			/* inp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				readfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (inp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_inp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#endif
+					}
+				skip_inp:
+					;
+				)
+			)
+			/* outp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				writefds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (outp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_outp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#endif
+					}
+				skip_outp:
+					;
+				)
+			)
+			/* exp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				exceptfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (exp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_exp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#endif
+					}
+				skip_exp:
+					;
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds_in);
+		kfree(tp_locvar->fds_out);
+		kfree(tp_locvar->fds_ex);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
+#define OVERRIDE_32_pselect6
+#define OVERRIDE_64_pselect6
+SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp, void * sig),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp, sig),
+	TP_locvar(
+		unsigned long *fds_in, *fds_out, *fds_ex;
+		unsigned long nr_bytes, nr_ulong;
+		unsigned int overflow;
+	),
+	TP_code_pre(
+		sc_inout(
+		{
+			int err;
+
+			tp_locvar->fds_in = NULL;
+			tp_locvar->fds_out = NULL;
+			tp_locvar->fds_ex = NULL;
+
+			tp_locvar->overflow = 0;
+
+			sc_out(
+				if (ret <= 0)
+					goto error;
+			)
+
+			if (n <= 0)
+				goto error;
+
+			/* Limit atomic memory allocation to one page */
+			if (DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) > PAGE_SIZE) {
+				tp_locvar->nr_bytes = PAGE_SIZE;
+				tp_locvar->nr_ulong = PAGE_SIZE / sizeof(unsigned long);
+				/* Inform the user that we did not output everything. */
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+				tp_locvar->nr_ulong = DIV_ROUND_UP((unsigned int) n,
+					BITS_PER_BYTE * sizeof(unsigned long));
+			}
+			/* On error or bogus input, don't copy anything. */
+			if (tp_locvar->nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+				goto error;
+			}
+
+			if (inp) {
+				tp_locvar->fds_in = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_in)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_in, inp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (outp) {
+				tp_locvar->fds_out = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_out)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_out, outp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (exp) {
+				tp_locvar->fds_ex = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_ex)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_ex, exp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			goto end;
+
+	error:
+		tp_locvar->nr_bytes = 0;
+		tp_locvar->nr_ulong = 0;
+	end:
+		/* bypass error: label at end of compound statement */
+		;
+		}
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_in(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+
+		sc_inout(
+			/* inp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				readfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (inp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_inp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#endif
+					}
+				skip_inp:
+					;
+				)
+			)
+			/* outp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				writefds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (outp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_outp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#endif
+					}
+				skip_outp:
+					;
+				)
+			)
+			/* exp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				exceptfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (exp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_exp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#endif
+					}
+				skip_exp:
+					;
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds_in);
+		kfree(tp_locvar->fds_out);
+		kfree(tp_locvar->fds_ex);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
 #endif /* CREATE_SYSCALL_TABLE */
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#3 lore raw

PATCH v5 3/5 Extract the FDs and flags from poll and ppoll

In reply to a message not in the archive

Instead of printing the pointer address of the poll set, extract all the FDs and flags from the poll set. For now, we only output the standardized set of events to limit the verbosity of the output, we also extract the raw value. When we switch to CTF2 we will be able to hide unset fields and then we will extract all the fields.

Here is an example of output with one FD:
syscall_entry_poll: {
timeout_msecs = -1, nfds = 1, fds_length = 1,
fds = [
[0] = { fd = 4, raw_events = 0x5, events = { POLLIN = 1, POLLPRI = 0, POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ]
}

syscall_exit_poll: {
ret = 1, nfds = 1, fds_length = 1,
fds = [ [0] = { fd = 4, raw_events = 0x4, events = { POLLIN = 0, POLLPRI = 0, POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ] }

---
 .../syscalls/headers/syscalls_pointers_override.h  | 360 +++++++++++++++++++++
 1 file changed, 360 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +360 -0
index ef4dc1c..6ade85c 100644
@@ -563,4 +563,364 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
 )
 #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
 
+#ifndef ONCE_LTTNG_TRACE_POLL_H
+#define ONCE_LTTNG_TRACE_POLL_H
+
+#define LTTNG_POLL_NRFLAGS (POLLNVAL + 1)
+#define POLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \
+	ilog2(LTTNG_POLL_NRFLAGS - 1)
+
+/*
+ * Only extract the values specified by iBCS2 for now.
+ */
+static struct lttng_event_field lttng_pollfd_flag_fields[] = {
+	[ilog2(POLLIN)] = {
+		.name = "POLLIN",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLPRI)] = {
+		.name = "POLLPRI",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLOUT)] = {
+		.name = "POLLOUT",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLERR)] = {
+		.name = "POLLERR",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLHUP)] = {
+		.name = "POLLHUP",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLNVAL)] = {
+		.name = "POLLNVAL",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(LTTNG_POLL_NRFLAGS)] = {
+		.name = "padding",
+		.type = __type_integer(int, POLL_FLAGS_PADDING_SIZE, 1, 0,
+				__LITTLE_ENDIAN, 10, none),
+	},
+};
+
+static struct lttng_event_field lttng_pollfd_fields[] = {
+	[0] = {
+		.name = "fd",
+		.type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
+	},
+	[1] = {
+		.name = "raw_events",
+		.type = __type_integer(short, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[2] = {
+		.name = "events",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_flag_fields),
+			.u._struct.fields = lttng_pollfd_flag_fields,
+		}
+	},
+};
+
+static struct lttng_type lttng_pollfd_elem = {
+	.atype = atype_struct,
+	.u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_fields),
+	.u._struct.fields = lttng_pollfd_fields,
+};
+#endif /* ONCE_LTTNG_TRACE_POLL_H */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
+#define OVERRIDE_32_poll
+#define OVERRIDE_64_poll
+SC_LTTNG_TRACEPOINT_EVENT_CODE(poll,
+	TP_PROTO(sc_exit(long ret,) struct pollfd __user * ufds,
+		unsigned int nfds, int timeout_msecs),
+	TP_ARGS(sc_exit(ret,) ufds, nfds, timeout_msecs),
+	TP_locvar(
+		unsigned int fds_length, fds_max_len;
+		struct pollfd *fds;
+		unsigned int alloc_fds;
+		unsigned int overflow;
+	),
+	TP_code_pre(
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) +
+				POLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		tp_locvar->fds = NULL;
+		tp_locvar->overflow = 0;
+
+		sc_in(
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = nfds;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_length * sizeof(struct pollfd);
+		)
+		/*
+		 * On exit, the number of active FDs is determined by ret,
+		 * nfds stays the same as the entry, but we only want to
+		 * output the FDs that are relevant.
+		 */
+		sc_out(
+			if (ret <= 0 || ret > nfds)
+				goto error;
+
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = ret;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_max_len * sizeof(struct pollfd);
+		)
+		{
+			int err;
+
+			tp_locvar->fds = kmalloc(tp_locvar->alloc_fds, GFP_ATOMIC);
+			if (!tp_locvar->fds)
+				goto error;
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->fds, ufds,
+				nfds * sizeof(struct pollfd));
+			if (err != 0)
+				goto error;
+		}
+		goto end;
+
+	error:
+		tp_locvar->fds_length = 0;
+		tp_locvar->fds_max_len = 0;
+	end:
+		;
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, timeout_msecs, timeout_msecs))
+		sc_inout(ctf_integer(unsigned int, nfds, nfds))
+		sc_inout(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_in(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_in(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+
+					ctf_align(int) /* Align on largest field in struct. */
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].events)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].events)
+					}
+				)
+			)
+		)
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+					unsigned int nr = 0;
+
+					ctf_align(int) /* Align on largest field in struct. */
+					/*
+					 * Iterate over the complete array, but only output
+					 * "ret" active FDs.
+					 */
+					for (i = 0; i < tp_locvar->fds_max_len; i++) {
+						if (!tp_locvar->fds[i].revents)
+							continue;
+						if (++nr > tp_locvar->fds_length)
+							break;
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].revents)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].revents)
+					}
+					/*
+					 * If there is a discrepancy between ret and the
+					 * content of revents (e.g. caused by userspace corrupting
+					 * the array from a concurrent thread), we have to output
+					 * zeros to keep the trace readable.
+					 */
+					for (i = nr; i < tp_locvar->fds_length - nr; i++) {
+						ctf_integer_type(int, 0)
+						ctf_integer_type(short, 0)
+						ctf_integer_bitfield_type(uint8_t, 0)
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
+#define OVERRIDE_32_ppoll
+#define OVERRIDE_64_ppoll
+SC_LTTNG_TRACEPOINT_EVENT_CODE(ppoll,
+	TP_PROTO(sc_exit(long ret,) struct pollfd __user * ufds,
+		unsigned int nfds, struct timespec * tsp, const sigset_t * sigmask, size_t sigsetsize),
+	TP_ARGS(sc_exit(ret,) ufds, nfds, tsp, sigmask, sigsetsize),
+	TP_locvar(
+		unsigned int fds_length, fds_max_len;
+		struct pollfd *fds;
+		unsigned int alloc_fds;
+		unsigned int overflow;
+	),
+	TP_code_pre(
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) +
+				POLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		tp_locvar->fds = NULL;
+		tp_locvar->overflow = 0;
+
+		sc_in(
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = nfds;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_length * sizeof(struct pollfd);
+		)
+		/*
+		 * On exit, the number of active FDs is determined by ret,
+		 * nfds stays the same as the entry, but we only want to
+		 * output the FDs that are relevant.
+		 */
+		sc_out(
+			if (ret <= 0 || ret > nfds)
+				goto error;
+
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = ret;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_max_len * sizeof(struct pollfd);
+		)
+		{
+			int err;
+
+			tp_locvar->fds = kmalloc(tp_locvar->alloc_fds, GFP_ATOMIC);
+			if (!tp_locvar->fds)
+				goto error;
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->fds, ufds,
+				nfds * sizeof(struct pollfd));
+			if (err != 0)
+				goto error;
+		}
+		goto end;
+
+	error:
+		tp_locvar->fds_length = 0;
+		tp_locvar->fds_max_len = 0;
+	end:
+		;
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(struct timespec *, tsp, tsp))
+		sc_in(ctf_integer(const sigset_t *, sigmask, sigmask))
+		sc_in(ctf_integer(size_t, sigsetsize, sigsetsize))
+		sc_inout(ctf_integer(unsigned int, nfds, nfds))
+		sc_inout(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_inout(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_in(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+
+					ctf_align(int) /* Align on largest field in struct. */
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].events)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].events)
+					}
+				)
+			)
+		)
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+					unsigned int nr = 0;
+
+					ctf_align(int) /* Align on largest field in struct. */
+					/*
+					 * Iterate over the complete array, but only output
+					 * "ret" active FDs.
+					 */
+					for (i = 0; i < tp_locvar->fds_max_len; i++) {
+						if (!tp_locvar->fds[i].revents)
+							continue;
+						if (++nr > tp_locvar->fds_length)
+							break;
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].revents)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].revents)
+					}
+					/*
+					 * If there is a discrepancy between ret and the
+					 * content of revents (e.g. caused by userspace corrupting
+					 * the array from a concurrent thread), we have to output
+					 * zeros to keep the trace readable.
+					 */
+					for (i = nr; i < tp_locvar->fds_length - nr; i++) {
+						ctf_integer_type(int, 0)
+						ctf_integer_type(short, 0)
+						ctf_integer_bitfield_type(uint8_t, 0)
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
 #endif /* CREATE_SYSCALL_TABLE */
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#4 lore raw

PATCH v5 4/5 Extract the payload for epoll_ctl

In reply to a message not in the archive

Map the operation to its name (EPOLL_CTL_*), extract the standard event flags (EPOLL*) and output the data in two different formats: FD as an int in decimal, and u64 in hex. The less standard event flags are not extracted yet, but we extract the raw value in hex for more advanced analyses.

Here is an example output:
syscall_entry_epoll_ctl: {
epfd = 4, op_enum = ( "EPOLL_CTL_ADD" : container = 1 ), fd = 0, event = { raw_events = 0x80000003,
events = { EPOLLIN = 1, EPOLLPRI = 1, EPOLLOUT = 0, EPOLLERR = 0,

    padding = 0 },

data_union = { u64 = 0x0, fd = 0 } }
}

syscall_exit_epoll_ctl: { ret = 0 }

---
 .../syscalls/headers/syscalls_pointers_override.h  | 139 +++++++++++++++++++++
 1 file changed, 139 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +139 -0
index 6ade85c..9fe0030 100644
@@ -923,4 +923,143 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(ppoll,
 )
 #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
 
+#include <linux/eventpoll.h>
+
+SC_LTTNG_TRACEPOINT_ENUM(lttng_epoll_op,
+	TP_ENUM_VALUES(
+		ctf_enum_value("EPOLL_CTL_ADD", EPOLL_CTL_ADD)
+		ctf_enum_value("EPOLL_CTL_DEL", EPOLL_CTL_DEL)
+		ctf_enum_value("EPOLL_CTL_MOD", EPOLL_CTL_MOD)
+	)
+)
+
+#ifndef ONCE_LTTNG_TRACE_EPOLL_CTL_H
+#define ONCE_LTTNG_TRACE_EPOLL_CTL_H
+
+#define LTTNG_EPOLL_NRFLAGS (POLLHUP + 1)
+#define EPOLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - ilog2(LTTNG_EPOLL_NRFLAGS - 1)
+
+/*
+ * Only extract the values specified by iBCS2 for now.
+ */
+static struct lttng_event_field lttng_epoll_ctl_events_fields[] = {
+	/* 0x0001 */
+	[ilog2(POLLIN)] = {
+		.name = "EPOLLIN",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0002 */
+	[ilog2(POLLPRI)] = {
+		.name = "EPOLLPRI",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0004 */
+	[ilog2(POLLOUT)] = {
+		.name = "EPOLLOUT",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0008 */
+	[ilog2(POLLERR)] = {
+		.name = "EPOLLERR",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0010 */
+	[ilog2(POLLHUP)] = {
+		.name = "EPOLLHUP",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(LTTNG_EPOLL_NRFLAGS)] = {
+		.name = "padding",
+		.type = __type_integer(int, EPOLL_FLAGS_PADDING_SIZE, 1, 0,
+				__LITTLE_ENDIAN, 10, none),
+	},
+
+};
+
+static struct lttng_event_field lttng_epoll_data_fields[] = {
+	[0] = {
+		.name = "u64",
+		.type = __type_integer(uint64_t, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[1] = {
+		.name = "fd",
+		.type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
+	},
+};
+
+static struct lttng_event_field epoll_ctl_fields[] = {
+	[0] = {
+		.name = "data_union",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
+			.u._struct.fields = lttng_epoll_data_fields,
+		}
+	},
+	[1] = {
+		.name = "raw_events",
+		.type = __type_integer(uint32_t, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[2] = {
+		.name = "events",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
+			.u._struct.fields = lttng_epoll_ctl_events_fields,
+		}
+	},
+};
+#endif /* ONCE_LTTNG_TRACE_EPOLL_CTL_H */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
+#define OVERRIDE_32_epoll_ctl
+#define OVERRIDE_64_epoll_ctl
+SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl,
+	TP_PROTO(sc_exit(long ret,) int epfd, int op, int fd,
+		struct epoll_event __user * uevent),
+	TP_ARGS(sc_exit(ret,) epfd, op, fd, uevent),
+	TP_locvar(
+		struct epoll_event event;
+		int err;
+	),
+	TP_code_pre(
+		tp_locvar->err = lib_ring_buffer_copy_from_user_check_nofault(
+			&tp_locvar->event, uevent, sizeof(struct epoll_event));
+		),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, epfd, epfd))
+		sc_in(ctf_enum(lttng_epoll_op, int, op_enum, op))
+		sc_in(ctf_integer(int, fd, fd))
+		sc_in(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_struct,
+					.u._struct.nr_fields = ARRAY_SIZE(epoll_ctl_fields),
+					.u._struct.fields = epoll_ctl_fields,
+				),
+				event,
+				ctf_custom_code(
+					ctf_align(uint64_t)
+					if (!tp_locvar->err) {
+						ctf_integer_type(uint64_t, tp_locvar->event.data)
+						ctf_integer_type(int, tp_locvar->event.data)
+						ctf_integer_bitfield_type(uint32_t,
+							cpu_to_le32(tp_locvar->event.events))
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) cpu_to_le32(tp_locvar->event.events))
+					} else {
+						ctf_integer_type(uint64_t, 0)
+						ctf_integer_type(int, 0)
+						ctf_integer_bitfield_type(uint32_t, 0)
+						ctf_integer_bitfield_type(uint8_t, 0)
+					}
+				)
+			)
+		)
+	),
+	TP_code_post()
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
 #endif /* CREATE_SYSCALL_TABLE */
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#5 lore raw

PATCH v5 5/5 Extract the payload of epoll_wait/epoll_pwait

In reply to a message not in the archive

When epoll_wait returns, extract the content of the "events" field (events set and data payload).

Here is an example output:
syscall_entry_epoll_wait: { epfd = 3, maxevents = 32, timeout = 100 }
syscall_exit_epoll_wait: { ret = 1, fds_length = 1,
fds = [ [0] = { raw_events = 0x1,

    events = { EPOLLIN = 1, EPOLLPRI = 0, EPOLLOUT = 0, EPOLLERR = 0,
      padding = 0 },
    data_union = { u64 = 0x100000005, fd = 5 } } ]
}
---
 .../syscalls/headers/syscalls_pointers_override.h  | 234 +++++++++++++++++++++
 1 file changed, 234 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +234 -0
index 9fe0030..68ba1a2 100644
@@ -1062,4 +1062,238 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl,
 )
 #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
 
+#ifndef ONCE_LTTNG_TRACE_EPOLL_H
+#define ONCE_LTTNG_TRACE_EPOLL_H
+
+static struct lttng_event_field lttng_epoll_wait_fields[] = {
+	[0] = {
+		.name = "data_union",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
+			.u._struct.fields = lttng_epoll_data_fields,
+		}
+	},
+	[1] = {
+		.name = "raw_events",
+		.type = __type_integer(uint32_t, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[2] = {
+		.name = "events",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
+			.u._struct.fields = lttng_epoll_ctl_events_fields,
+		}
+	},
+};
+
+static struct lttng_type lttng_epoll_wait_elem = {
+	.atype = atype_struct,
+	.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_wait_fields),
+	.u._struct.fields = lttng_epoll_wait_fields,
+};
+
+#endif /* ONCE_LTTNG_TRACE_EPOLL_H */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
+#define OVERRIDE_32_epoll_wait
+#define OVERRIDE_64_epoll_wait
+SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_wait,
+	TP_PROTO(sc_exit(long ret,) int epfd, struct epoll_event __user * uevents,
+		int maxevents, int timeout),
+	TP_ARGS(sc_exit(ret,) epfd, uevents, maxevents, timeout),
+	TP_locvar(
+		sc_out(
+			unsigned int fds_length, overflow;
+			struct epoll_event *events;
+		)
+	),
+	TP_code_pre(
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_epoll_ctl_events_fields) - 1) +
+				EPOLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		sc_out({
+			int err;
+			unsigned long maxalloc;
+
+			tp_locvar->fds_length = 0;
+			tp_locvar->events = NULL;
+			tp_locvar->overflow = 0;
+
+			if (maxevents <= 0 || ret <= 0 || ret > maxevents)
+				goto skip_code;
+
+			if ((maxevents * sizeof(struct epoll_event)) > PAGE_SIZE) {
+				maxalloc = PAGE_SIZE / sizeof(struct epoll_event);
+				if (ret > maxalloc) {
+					tp_locvar->fds_length = maxalloc;
+					tp_locvar->overflow = 1;
+				} else {
+					tp_locvar->fds_length = ret;
+				}
+			} else {
+				maxalloc = maxevents;
+				tp_locvar->fds_length = ret;
+			}
+
+			tp_locvar->events = kmalloc(
+				maxalloc * sizeof(struct epoll_event),
+				GFP_ATOMIC);
+			if (!tp_locvar->events) {
+				tp_locvar->fds_length = 0;
+				goto skip_code;
+			}
+
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->events, uevents,
+				maxevents * sizeof(struct epoll_event));
+			if (err != 0)
+				tp_locvar->fds_length = 0;
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, epfd, epfd))
+		sc_in(ctf_integer(int, maxevents, maxevents))
+		sc_in(ctf_integer(int, timeout, timeout))
+		sc_out(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_out(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name =
+						"fds_length",
+					.u.sequence_compound.elem_type =
+						&lttng_epoll_wait_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+
+					ctf_align(uint64_t)
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(uint64_t, tp_locvar->events[i].data)
+						ctf_integer_type(int, tp_locvar->events[i].data)
+						ctf_integer_bitfield_type(uint32_t,
+							cpu_to_le32(tp_locvar->events[i].events))
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) cpu_to_le32(tp_locvar->events[i].events))
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		sc_out(
+			kfree(tp_locvar->events);
+		)
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
+#define OVERRIDE_32_epoll_pwait
+#define OVERRIDE_64_epoll_pwait
+SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_pwait,
+	TP_PROTO(sc_exit(long ret,) int epfd, struct epoll_event __user * uevents,
+		int maxevents, int timeout, const sigset_t * sigmask, size_t sigsetsize),
+	TP_ARGS(sc_exit(ret,) epfd, uevents, maxevents, timeout, sigmask, sigsetsize),
+	TP_locvar(
+		sc_out(
+			unsigned int fds_length, overflow;
+			struct epoll_event *events;
+		)
+	),
+	TP_code_pre(
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_epoll_ctl_events_fields) - 1) +
+				EPOLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		sc_out({
+			int err;
+			unsigned long maxalloc;
+
+			tp_locvar->fds_length = 0;
+			tp_locvar->events = NULL;
+			tp_locvar->overflow = 0;
+
+			if (maxevents <= 0 || ret <= 0 || ret > maxevents)
+				goto skip_code;
+
+			if ((maxevents * sizeof(struct epoll_event)) > PAGE_SIZE) {
+				maxalloc = PAGE_SIZE / sizeof(struct epoll_event);
+				if (ret > maxalloc) {
+					tp_locvar->fds_length = maxalloc;
+					tp_locvar->overflow = 1;
+				} else {
+					tp_locvar->fds_length = ret;
+				}
+			} else {
+				maxalloc = maxevents;
+				tp_locvar->fds_length = ret;
+			}
+
+			tp_locvar->events = kmalloc(
+				maxalloc * sizeof(struct epoll_event),
+				GFP_ATOMIC);
+			if (!tp_locvar->events) {
+				tp_locvar->fds_length = 0;
+				goto skip_code;
+			}
+
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->events, uevents,
+				maxevents * sizeof(struct epoll_event));
+			if (err != 0)
+				tp_locvar->fds_length = 0;
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, epfd, epfd))
+		sc_in(ctf_integer(int, maxevents, maxevents))
+		sc_in(ctf_integer(int, timeout, timeout))
+		sc_in(ctf_integer(const sigset_t *, sigmask, sigmask))
+		sc_in(ctf_integer(size_t, sigsetsize, sigsetsize))
+		sc_out(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_out(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name =
+						"fds_length",
+					.u.sequence_compound.elem_type =
+						&lttng_epoll_wait_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+
+					ctf_align(uint64_t)
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(uint64_t, tp_locvar->events[i].data)
+						ctf_integer_type(int, tp_locvar->events[i].data)
+						ctf_integer_bitfield_type(uint32_t,
+							cpu_to_le32(tp_locvar->events[i].events))
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) cpu_to_le32(tp_locvar->events[i].events))
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		sc_out(
+			kfree(tp_locvar->events);
+		)
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
 #endif /* CREATE_SYSCALL_TABLE */
Signature · 6 lines
1.9.1

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

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

#7 lore raw

Re: [PATCH lttng-modules v5 2/5] Extract the FD sets in select and pselect6

Review

Quoted 4 lines
(quoted diff) +4 -0
+			if (inp) {
+				tp_locvar->fds_in = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);

I replaced "GFP_ATOMIC" by "GFP_ATOMIC | GFP_NOWAIT" for every allocation in this patch serie because ATOMIC does not imply NOWAIT.

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

#8 lore raw

Re: [PATCH lttng-modules v5 2/5] Extract the FD sets in select and pselect6

In reply to a message not in the archive
Quoted 38 lines · ----- On Apr 22, 2016, at 8:16 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 uint8_t (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 5 to 19 (0xFFFF0), it returns that one FD is ready: FD 12 (0x1000).

syscall_entry_select: {
n = 20,
_fdset_in_length = 3, fdset_in = [ [0] = 0xF0, [1] = 0xFF, [2] = 0xF ], _fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}

syscall_exit_select: {
ret = 1,
_fdset_in_length = 3, fdset_in = [ [0] = 0x0, [1] = 0x10, [2] = 0x0 ], _fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}

---
.../syscalls/headers/syscalls_pointers_override.h | 510 +++++++++++++++++++++

1 file changed, 510 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +1 -0
index bf5c632..ef4dc1c 100644
@@ -53,4 +53,514 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe2,
 	)
 )
 
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 66

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+#define OVERRIDE_32_select
+#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, *fds_out, *fds_ex;
+		unsigned long nr_bytes, nr_ulong;
+		unsigned int overflow;

Change for uint8_t for overflow.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 76

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+	),
+	TP_code_pre(
+		sc_inout(
+		{
+			int err;
+
+			tp_locvar->fds_in = NULL;
+			tp_locvar->fds_out = NULL;
+			tp_locvar->fds_ex = NULL;
+

remove newline.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 88

Quoted 12 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +12 -0
+			tp_locvar->overflow = 0;
+
+			sc_out(
+				if (ret <= 0)
+					goto error;
+			)
+
+			if (n <= 0)
+				goto error;
+
+			/* Limit atomic memory allocation to one page */
+			if (DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) > PAGE_SIZE) {

Put DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) into local variable.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 99

Quoted 11 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +11 -0
+				tp_locvar->nr_bytes = PAGE_SIZE;
+				tp_locvar->nr_ulong = PAGE_SIZE / sizeof(unsigned long);
+				/* Inform the user that we did not output everything. */
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+				tp_locvar->nr_ulong = DIV_ROUND_UP((unsigned int) n,
+					BITS_PER_BYTE * sizeof(unsigned long));
+			}
+			/* On error or bogus input, don't copy anything. */
+			if (tp_locvar->nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {

Replace 8 by BITS_PER_BYTE

Move this check before the comparison with PAGE_SIZE. A "n" larger than 1023 is an error....
Test on "n" rather than nr_bytes.

nr_bytes will therefore never be over on page on linux.
We could put a WARN_ON_ONCE() and goto error for it instead of the ceiling.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 106

Quoted 7 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +7 -0
+				goto error;
+			}
+
+			if (inp) {
+				tp_locvar->fds_in = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);

| GFP_NOWAIT as discussed.

Quoted 13 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +13 -0
+				if (!tp_locvar->fds_in)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_in, inp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (outp) {
+				tp_locvar->fds_out = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);

.....

Quoted 13 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +13 -0
+				if (!tp_locvar->fds_out)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_out, outp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (exp) {
+				tp_locvar->fds_ex = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);

.........

Quoted 6 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +6 -0
+				if (!tp_locvar->fds_ex)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_ex, exp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+				if (err != 0)
+					goto error;
+			}
+			goto end;
+
+	error:
+		tp_locvar->nr_bytes = 0;
+		tp_locvar->nr_ulong = 0;
+	end:
+		/* bypass error: label at end of compound statement */

Reword to /* Label at end of compound statement. */

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 1 line
instrumentation/syscalls/headers/syscalls_pointers_override.h +1 -0
+		;

Mod line to:

end: ; /* Label at end of compound statement. */

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 7 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +7 -0
+		}
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_integer(int, overflow, tp_locvar->overflow))

uint8_t

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 9 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +9 -0
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+
+		sc_inout(
+			/* inp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),

uint8_t is enough. (1024/8=128)

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				readfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (inp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)

uint8_t

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 3 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +3 -0
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)

uint8_t

Quoted 17 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +17 -0
+						ctf_align(uint8_t)
+						goto skip_inp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#endif
+					}
+				skip_inp:
+					;
+				)

3 macros (nested) rather than cut n paste.

Quoted 107 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +106 -0
+			)
+			/* outp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				writefds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (outp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_outp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#endif
+					}
+				skip_outp:
+					;
+				)
+			)
+			/* exp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				exceptfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (exp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_exp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#endif
+					}
+				skip_exp:
+					;
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds_in);
+		kfree(tp_locvar->fds_out);
+		kfree(tp_locvar->fds_ex);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64)

|| defined(CONFIG_ARM)

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 7 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +7 -0
+#define OVERRIDE_32_pselect6
+#define OVERRIDE_64_pselect6
+SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp, void * sig),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp, sig),
+	TP_locvar(

Please combine into a macro with select.

Quoted 233 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +233 -0
+		unsigned long *fds_in, *fds_out, *fds_ex;
+		unsigned long nr_bytes, nr_ulong;
+		unsigned int overflow;
+	),
+	TP_code_pre(
+		sc_inout(
+		{
+			int err;
+
+			tp_locvar->fds_in = NULL;
+			tp_locvar->fds_out = NULL;
+			tp_locvar->fds_ex = NULL;
+
+			tp_locvar->overflow = 0;
+
+			sc_out(
+				if (ret <= 0)
+					goto error;
+			)
+
+			if (n <= 0)
+				goto error;
+
+			/* Limit atomic memory allocation to one page */
+			if (DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) > PAGE_SIZE) {
+				tp_locvar->nr_bytes = PAGE_SIZE;
+				tp_locvar->nr_ulong = PAGE_SIZE / sizeof(unsigned long);
+				/* Inform the user that we did not output everything. */
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+				tp_locvar->nr_ulong = DIV_ROUND_UP((unsigned int) n,
+					BITS_PER_BYTE * sizeof(unsigned long));
+			}
+			/* On error or bogus input, don't copy anything. */
+			if (tp_locvar->nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+				goto error;
+			}
+
+			if (inp) {
+				tp_locvar->fds_in = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_in)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_in, inp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (outp) {
+				tp_locvar->fds_out = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_out)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_out, outp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (exp) {
+				tp_locvar->fds_ex = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_ex)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_ex, exp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			goto end;
+
+	error:
+		tp_locvar->nr_bytes = 0;
+		tp_locvar->nr_ulong = 0;
+	end:
+		/* bypass error: label at end of compound statement */
+		;
+		}
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_in(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+
+		sc_inout(
+			/* inp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				readfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (inp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_inp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#endif
+					}
+				skip_inp:
+					;
+				)
+			)
+			/* outp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				writefds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (outp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_outp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#endif
+					}
+				skip_outp:
+					;
+				)
+			)
+			/* exp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				exceptfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (exp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_exp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#endif
+					}

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+				skip_exp:
+					;
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds_in);
+		kfree(tp_locvar->fds_out);
+		kfree(tp_locvar->fds_ex);

Thanks,

Mathieu

Quoted 8 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +3 -0
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
#endif /* CREATE_SYSCALL_TABLE */
--
1.9.1

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

#10 lore raw

Re: [PATCH lttng-modules v5 2/5] Extract the FD sets in select and pselect6

Quoted 212 lines · ----- On Apr 29, 2016, at 2:13 PM, Mathieu Desnoyers…

----- On Apr 22, 2016, at 8:16 PM, Julien Desfossez [email protected]

Quoted 38 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 uint8_t (1024 FDs is the limit in the kernel).

In this example, we select in input FDs 5 to 19 (0xFFFF0), it returns that one FD is ready: FD 12 (0x1000).

syscall_entry_select: {
n = 20,
_fdset_in_length = 3, fdset_in = [ [0] = 0xF0, [1] = 0xFF, [2] = 0xF ], _fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}

syscall_exit_select: {
ret = 1,
_fdset_in_length = 3, fdset_in = [ [0] = 0x0, [1] = 0x10, [2] = 0x0 ], _fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}

---
.../syscalls/headers/syscalls_pointers_override.h | 510 +++++++++++++++++++++

1 file changed, 510 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +1 -0
index bf5c632..ef4dc1c 100644
@@ -53,4 +53,514 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe2,
 	)
 )
 
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 66

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+#define OVERRIDE_32_select
+#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, *fds_out, *fds_ex;
+		unsigned long nr_bytes, nr_ulong;
+		unsigned int overflow;

Change for uint8_t for overflow.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 76

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+	),
+	TP_code_pre(
+		sc_inout(
+		{
+			int err;
+
+			tp_locvar->fds_in = NULL;
+			tp_locvar->fds_out = NULL;
+			tp_locvar->fds_ex = NULL;
+

remove newline.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 88

Quoted 12 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +12 -0
+			tp_locvar->overflow = 0;
+
+			sc_out(
+				if (ret <= 0)
+					goto error;
+			)
+
+			if (n <= 0)
+				goto error;
+
+			/* Limit atomic memory allocation to one page */
+			if (DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) > PAGE_SIZE) {

Put DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) into local variable.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 99

Quoted 11 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +11 -0
+				tp_locvar->nr_bytes = PAGE_SIZE;
+				tp_locvar->nr_ulong = PAGE_SIZE / sizeof(unsigned long);
+				/* Inform the user that we did not output everything. */
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+				tp_locvar->nr_ulong = DIV_ROUND_UP((unsigned int) n,
+					BITS_PER_BYTE * sizeof(unsigned long));
+			}
+			/* On error or bogus input, don't copy anything. */
+			if (tp_locvar->nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {

Replace 8 by BITS_PER_BYTE

Move this check before the comparison with PAGE_SIZE. A "n" larger than 1023 is an error....
Test on "n" rather than nr_bytes.

nr_bytes will therefore never be over on page on linux.
We could put a WARN_ON_ONCE() and goto error for it instead of the ceiling.

instrumentation/syscalls/headers/syscalls_pointers_override.h SC_LTTNG_TRACEPOINT_EVENT(pipe2, · line 106

Quoted 7 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +7 -0
+				goto error;
+			}
+
+			if (inp) {
+				tp_locvar->fds_in = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);

| GFP_NOWAIT as discussed.

Quoted 13 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +13 -0
+				if (!tp_locvar->fds_in)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_in, inp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (outp) {
+				tp_locvar->fds_out = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);

.....

Quoted 13 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +13 -0
+				if (!tp_locvar->fds_out)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_out, outp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (exp) {
+				tp_locvar->fds_ex = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);

.........

Quoted 6 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +6 -0
+				if (!tp_locvar->fds_ex)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_ex, exp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+				if (err != 0)
+					goto error;
+			}
+			goto end;
+
+	error:
+		tp_locvar->nr_bytes = 0;
+		tp_locvar->nr_ulong = 0;
+	end:
+		/* bypass error: label at end of compound statement */

Reword to /* Label at end of compound statement. */

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 1 line
instrumentation/syscalls/headers/syscalls_pointers_override.h +1 -0
+		;

Mod line to:

end: ; /* Label at end of compound statement. */

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 7 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +7 -0
+		}
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_inout(ctf_integer(int, overflow, tp_locvar->overflow))

uint8_t

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 9 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +9 -0
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+
+		sc_inout(
+			/* inp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),

uint8_t is enough. (1024/8=128)

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				readfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (inp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)

uint8_t

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 3 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +3 -0
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)

uint8_t

Quoted 13 lines

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 13 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +13 -0
+						ctf_align(uint8_t)
+						goto skip_inp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}

While technically correct, please do the check before "writing" the field.

Move the check just before the ctf_user_integer_type(), and post-increment it. (both little and big endian).

Mathieu

Quoted 395 lines
Quoted 4 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +4 -0
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#endif
+					}
+				skip_inp:
+					;
+				)

3 macros (nested) rather than cut n paste.

Quoted 107 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +106 -0
+			)
+			/* outp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				writefds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (outp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_outp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#endif
+					}
+				skip_outp:
+					;
+				)
+			)
+			/* exp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				exceptfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (exp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_exp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#endif
+					}
+				skip_exp:
+					;
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds_in);
+		kfree(tp_locvar->fds_out);
+		kfree(tp_locvar->fds_ex);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64)

|| defined(CONFIG_ARM)

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 7 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +7 -0
+#define OVERRIDE_32_pselect6
+#define OVERRIDE_64_pselect6
+SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
+	TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+		fd_set __user * exp, struct timeval * tvp, void * sig),
+	TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp, sig),
+	TP_locvar(

Please combine into a macro with select.

Quoted 233 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +233 -0
+		unsigned long *fds_in, *fds_out, *fds_ex;
+		unsigned long nr_bytes, nr_ulong;
+		unsigned int overflow;
+	),
+	TP_code_pre(
+		sc_inout(
+		{
+			int err;
+
+			tp_locvar->fds_in = NULL;
+			tp_locvar->fds_out = NULL;
+			tp_locvar->fds_ex = NULL;
+
+			tp_locvar->overflow = 0;
+
+			sc_out(
+				if (ret <= 0)
+					goto error;
+			)
+
+			if (n <= 0)
+				goto error;
+
+			/* Limit atomic memory allocation to one page */
+			if (DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE) > PAGE_SIZE) {
+				tp_locvar->nr_bytes = PAGE_SIZE;
+				tp_locvar->nr_ulong = PAGE_SIZE / sizeof(unsigned long);
+				/* Inform the user that we did not output everything. */
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+				tp_locvar->nr_ulong = DIV_ROUND_UP((unsigned int) n,
+					BITS_PER_BYTE * sizeof(unsigned long));
+			}
+			/* On error or bogus input, don't copy anything. */
+			if (tp_locvar->nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+				goto error;
+			}
+
+			if (inp) {
+				tp_locvar->fds_in = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_in)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_in, inp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (outp) {
+				tp_locvar->fds_out = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_out)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_out, outp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			if (exp) {
+				tp_locvar->fds_ex = kmalloc(
+						tp_locvar->nr_ulong * sizeof(unsigned long),
+						GFP_ATOMIC);
+				if (!tp_locvar->fds_ex)
+					goto error;
+
+				err = lib_ring_buffer_copy_from_user_check_nofault(
+						tp_locvar->fds_ex, exp,
+						tp_locvar->nr_ulong * sizeof(unsigned long));
+				if (err != 0)
+					goto error;
+			}
+			goto end;
+
+	error:
+		tp_locvar->nr_bytes = 0;
+		tp_locvar->nr_ulong = 0;
+	end:
+		/* bypass error: label at end of compound statement */
+		;
+		}
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, n, n))
+		sc_in(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+
+		sc_inout(
+			/* inp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				readfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (inp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_inp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (inp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_inp;
+							}
+						}
+#endif
+					}
+				skip_inp:
+					;
+				)
+			)
+			/* outp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				writefds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (outp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_outp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (outp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_outp;
+							}
+						}
+#endif
+					}
+				skip_outp:
+					;
+				)
+			)
+			/* exp */
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence,
+					.u.sequence.length_type = __type_integer(
+						uint16_t, 0, 0, 0, __BYTE_ORDER, 10, none),
+					.u.sequence.elem_type = __type_integer(uint8_t, 0, 0, 0,
+						__BYTE_ORDER, 16, none),
+				),
+				exceptfds,
+				ctf_custom_code(
+					unsigned int src;
+					unsigned int nr_bytes_out = 0;
+
+					if (exp) {
+						ctf_integer_type(uint16_t, tp_locvar->nr_bytes)
+						ctf_align(uint8_t)
+					} else {
+						ctf_integer_type(uint16_t, 0)
+						ctf_align(uint8_t)
+						goto skip_exp;
+					}
+
+					for (src = 0; src < tp_locvar->nr_ulong; src++) {
+						int dst;
+#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+						for (dst = 0; dst < sizeof(long); dst++) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#else
+						for (dst = sizeof(long); dst >= 0; dst--) {
+							ctf_user_integer_type(uint8_t,
+								((uint8_t __user *) (exp->fds_bits + src))[dst]);
+							if (++nr_bytes_out >= tp_locvar->nr_bytes) {
+								goto skip_exp;
+							}
+						}
+#endif
+					}

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+				skip_exp:
+					;
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds_in);
+		kfree(tp_locvar->fds_out);
+		kfree(tp_locvar->fds_ex);

Thanks,

Mathieu

Quoted 8 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +3 -0
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
#endif /* CREATE_SYSCALL_TABLE */
--
1.9.1

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

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

#12 lore raw

Re: [PATCH lttng-modules v5 3/5] Extract the FDs and flags from poll and ppoll

Quoted 103 lines · ----- On Apr 22, 2016, at 8:16 PM, Julien Desfossez [email protected]…

Instead of printing the pointer address of the poll set, extract all the FDs and flags from the poll set. For now, we only output the standardized set of events to limit the verbosity of the output, we also extract the raw value. When we switch to CTF2 we will be able to hide unset fields and then we will extract all the fields.

Here is an example of output with one FD:
syscall_entry_poll: {
timeout_msecs = -1, nfds = 1, fds_length = 1,
fds = [
[0] = { fd = 4, raw_events = 0x5, events = { POLLIN = 1, POLLPRI = 0, POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ]
}

syscall_exit_poll: {
ret = 1, nfds = 1, fds_length = 1,
fds = [ [0] = { fd = 4, raw_events = 0x4, events = { POLLIN = 0, POLLPRI = 0, POLLOUT = 1, POLLERR = 0, POLLHUP = 0, padding = 0 } } ] }

---
.../syscalls/headers/syscalls_pointers_override.h | 360 +++++++++++++++++++++

1 file changed, 360 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +0 -0
index ef4dc1c..6ade85c 100644
@@ -563,4 +563,364 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
 )
 #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */

instrumentation/syscalls/headers/syscalls_pointers_override.h +69 -0
+#ifndef ONCE_LTTNG_TRACE_POLL_H
+#define ONCE_LTTNG_TRACE_POLL_H
+
+#define LTTNG_POLL_NRFLAGS (POLLNVAL + 1)
+#define POLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) - \
+	ilog2(LTTNG_POLL_NRFLAGS - 1)
+
+/*
+ * Only extract the values specified by iBCS2 for now.
+ */
+static struct lttng_event_field lttng_pollfd_flag_fields[] = {
+	[ilog2(POLLIN)] = {
+		.name = "POLLIN",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLPRI)] = {
+		.name = "POLLPRI",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLOUT)] = {
+		.name = "POLLOUT",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLERR)] = {
+		.name = "POLLERR",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLHUP)] = {
+		.name = "POLLHUP",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(POLLNVAL)] = {
+		.name = "POLLNVAL",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(LTTNG_POLL_NRFLAGS)] = {
+		.name = "padding",
+		.type = __type_integer(int, POLL_FLAGS_PADDING_SIZE, 1, 0,
+				__LITTLE_ENDIAN, 10, none),
+	},
+};
+
+static struct lttng_event_field lttng_pollfd_fields[] = {
+	[0] = {
+		.name = "fd",
+		.type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
+	},
+	[1] = {
+		.name = "raw_events",
+		.type = __type_integer(short, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[2] = {
+		.name = "events",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_flag_fields),
+			.u._struct.fields = lttng_pollfd_flag_fields,
+		}
+	},
+};
+
+static struct lttng_type lttng_pollfd_elem = {
+	.atype = atype_struct,
+	.u._struct.nr_fields = ARRAY_SIZE(lttng_pollfd_fields),
+	.u._struct.fields = lttng_pollfd_fields,
+};
+#endif /* ONCE_LTTNG_TRACE_POLL_H */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+#define OVERRIDE_32_poll
+#define OVERRIDE_64_poll
+SC_LTTNG_TRACEPOINT_EVENT_CODE(poll,
+	TP_PROTO(sc_exit(long ret,) struct pollfd __user * ufds,
+		unsigned int nfds, int timeout_msecs),
+	TP_ARGS(sc_exit(ret,) ufds, nfds, timeout_msecs),
+	TP_locvar(
+		unsigned int fds_length, fds_max_len;
+		struct pollfd *fds;
+		unsigned int alloc_fds;

Move alloc_fds to other uint.

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 1 line
instrumentation/syscalls/headers/syscalls_pointers_override.h +1 -0
+		unsigned int overflow;

becomes uint8_t.

Quoted 42 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +42 -0
+	),
+	TP_code_pre(
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) +
+				POLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		tp_locvar->fds = NULL;
+		tp_locvar->overflow = 0;
+
+		sc_in(
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = nfds;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_length * sizeof(struct pollfd);
+		)
+		/*
+		 * On exit, the number of active FDs is determined by ret,
+		 * nfds stays the same as the entry, but we only want to
+		 * output the FDs that are relevant.
+		 */
+		sc_out(
+			if (ret <= 0 || ret > nfds)
+				goto error;
+
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = ret;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_max_len * sizeof(struct pollfd);
+		)
+		{
+			int err;
+
+			tp_locvar->fds = kmalloc(tp_locvar->alloc_fds, GFP_ATOMIC);

...........

Quoted 12 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +12 -0
+			if (!tp_locvar->fds)
+				goto error;
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->fds, ufds,
+				nfds * sizeof(struct pollfd));
+			if (err != 0)
+				goto error;
+		}
+		goto end;
+
+	error:
+		tp_locvar->fds_length = 0;

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+		tp_locvar->fds_max_len = 0;
+	end:
+		;
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, timeout_msecs, timeout_msecs))
+		sc_inout(ctf_integer(unsigned int, nfds, nfds))
+		sc_inout(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_in(ctf_integer(int, overflow, tp_locvar->overflow))

uint8_t

Quoted 32 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +32 -0
+		sc_in(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+
+					ctf_align(int) /* Align on largest field in struct. */
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].events)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].events)
+					}
+				)
+			)
+		)
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+					unsigned int nr = 0;

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+
+					ctf_align(int) /* Align on largest field in struct. */
+					/*
+					 * Iterate over the complete array, but only output
+					 * "ret" active FDs.
+					 */
+					for (i = 0; i < tp_locvar->fds_max_len; i++) {
+						if (!tp_locvar->fds[i].revents)
+							continue;
+						if (++nr > tp_locvar->fds_length)

Change for: if (nr++ >= tp_locvar->fds_length)

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 13 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +13 -0
+							break;
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].revents)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].revents)
+					}
+					/*
+					 * If there is a discrepancy between ret and the
+					 * content of revents (e.g. caused by userspace corrupting
+					 * the array from a concurrent thread), we have to output
+					 * zeros to keep the trace readable.
+					 */
+					for (i = nr; i < tp_locvar->fds_length - nr; i++) {

Remove the "- nr".

Quoted 22 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +15 -0
+						ctf_integer_type(int, 0)
+						ctf_integer_type(short, 0)
+						ctf_integer_bitfield_type(uint8_t, 0)
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64)

|| defined(CONFIG_ARM)

instrumentation/syscalls/headers/syscalls_pointers_override.h +5 -0
+#define OVERRIDE_32_ppoll
+#define OVERRIDE_64_ppoll
+SC_LTTNG_TRACEPOINT_EVENT_CODE(ppoll,
+	TP_PROTO(sc_exit(long ret,) struct pollfd __user * ufds,
+		unsigned int nfds, struct timespec * tsp, const sigset_t * sigmask, size_t

sigsetsize),

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 8 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +8 -0
+	TP_ARGS(sc_exit(ret,) ufds, nfds, tsp, sigmask, sigsetsize),
+	TP_locvar(
+		unsigned int fds_length, fds_max_len;
+		struct pollfd *fds;
+		unsigned int alloc_fds;
+		unsigned int overflow;
+	),
+	TP_code_pre(

Use macros to remove code duplication.

Thanks,

Mathieu

Quoted 137 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +132 -0
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_pollfd_flag_fields) - 1) +
+				POLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		tp_locvar->fds = NULL;
+		tp_locvar->overflow = 0;
+
+		sc_in(
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = nfds;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_length * sizeof(struct pollfd);
+		)
+		/*
+		 * On exit, the number of active FDs is determined by ret,
+		 * nfds stays the same as the entry, but we only want to
+		 * output the FDs that are relevant.
+		 */
+		sc_out(
+			if (ret <= 0 || ret > nfds)
+				goto error;
+
+			if (nfds * sizeof(struct pollfd) > PAGE_SIZE) {
+				tp_locvar->fds_length = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->fds_max_len = PAGE_SIZE / sizeof(struct pollfd);
+				tp_locvar->overflow = 1;
+			} else {
+				tp_locvar->fds_length = ret;
+				tp_locvar->fds_max_len = nfds;
+			}
+			tp_locvar->alloc_fds = tp_locvar->fds_max_len * sizeof(struct pollfd);
+		)
+		{
+			int err;
+
+			tp_locvar->fds = kmalloc(tp_locvar->alloc_fds, GFP_ATOMIC);
+			if (!tp_locvar->fds)
+				goto error;
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->fds, ufds,
+				nfds * sizeof(struct pollfd));
+			if (err != 0)
+				goto error;
+		}
+		goto end;
+
+	error:
+		tp_locvar->fds_length = 0;
+		tp_locvar->fds_max_len = 0;
+	end:
+		;
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(struct timespec *, tsp, tsp))
+		sc_in(ctf_integer(const sigset_t *, sigmask, sigmask))
+		sc_in(ctf_integer(size_t, sigsetsize, sigsetsize))
+		sc_inout(ctf_integer(unsigned int, nfds, nfds))
+		sc_inout(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_inout(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_in(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+
+					ctf_align(int) /* Align on largest field in struct. */
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].events)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].events)
+					}
+				)
+			)
+		)
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name = "fds_length",
+					.u.sequence_compound.elem_type = &lttng_pollfd_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+					unsigned int nr = 0;
+
+					ctf_align(int) /* Align on largest field in struct. */
+					/*
+					 * Iterate over the complete array, but only output
+					 * "ret" active FDs.
+					 */
+					for (i = 0; i < tp_locvar->fds_max_len; i++) {
+						if (!tp_locvar->fds[i].revents)
+							continue;
+						if (++nr > tp_locvar->fds_length)
+							break;
+						ctf_integer_type(int, tp_locvar->fds[i].fd)
+						ctf_integer_type(short, tp_locvar->fds[i].revents)
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) tp_locvar->fds[i].revents)
+					}
+					/*
+					 * If there is a discrepancy between ret and the
+					 * content of revents (e.g. caused by userspace corrupting
+					 * the array from a concurrent thread), we have to output
+					 * zeros to keep the trace readable.
+					 */
+					for (i = nr; i < tp_locvar->fds_length - nr; i++) {
+						ctf_integer_type(int, 0)
+						ctf_integer_type(short, 0)
+						ctf_integer_bitfield_type(uint8_t, 0)
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		kfree(tp_locvar->fds);
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
#endif /* CREATE_SYSCALL_TABLE */
--
1.9.1

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

#14 lore raw

Re: [PATCH lttng-modules v5 4/5] Extract the payload for epoll_ctl

Quoted 47 lines · ----- On Apr 22, 2016, at 8:16 PM, Julien Desfossez [email protected]…

Map the operation to its name (EPOLL_CTL_*), extract the standard event flags (EPOLL*) and output the data in two different formats: FD as an int in decimal, and u64 in hex. The less standard event flags are not extracted yet, but we extract the raw value in hex for more advanced analyses.

Here is an example output:
syscall_entry_epoll_ctl: {
epfd = 4, op_enum = ( "EPOLL_CTL_ADD" : container = 1 ), fd = 0, event = { raw_events = 0x80000003,
events = { EPOLLIN = 1, EPOLLPRI = 1, EPOLLOUT = 0, EPOLLERR = 0,
padding = 0 },
data_union = { u64 = 0x0, fd = 0 } }
}

syscall_exit_epoll_ctl: { ret = 0 }

---
.../syscalls/headers/syscalls_pointers_override.h | 139 +++++++++++++++++++++

1 file changed, 139 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +0 -0
index 6ade85c..9fe0030 100644
@@ -923,4 +923,143 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(ppoll,
 )
 #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */

instrumentation/syscalls/headers/syscalls_pointers_override.h +15 -0
+#include <linux/eventpoll.h>
+
+SC_LTTNG_TRACEPOINT_ENUM(lttng_epoll_op,
+	TP_ENUM_VALUES(
+		ctf_enum_value("EPOLL_CTL_ADD", EPOLL_CTL_ADD)
+		ctf_enum_value("EPOLL_CTL_DEL", EPOLL_CTL_DEL)
+		ctf_enum_value("EPOLL_CTL_MOD", EPOLL_CTL_MOD)
+	)
+)
+
+#ifndef ONCE_LTTNG_TRACE_EPOLL_CTL_H
+#define ONCE_LTTNG_TRACE_EPOLL_CTL_H
+
+#define LTTNG_EPOLL_NRFLAGS (POLLHUP + 1)
+#define EPOLL_FLAGS_PADDING_SIZE (sizeof(uint8_t) * BITS_PER_BYTE) -
Quoted 1 line

ilog2(LTTNG_EPOLL_NRFLAGS - 1)

newline with \ (too long)

Quoted 101 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +74 -0
+
+/*
+ * Only extract the values specified by iBCS2 for now.
+ */
+static struct lttng_event_field lttng_epoll_ctl_events_fields[] = {
+	/* 0x0001 */
+	[ilog2(POLLIN)] = {
+		.name = "EPOLLIN",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0002 */
+	[ilog2(POLLPRI)] = {
+		.name = "EPOLLPRI",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0004 */
+	[ilog2(POLLOUT)] = {
+		.name = "EPOLLOUT",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0008 */
+	[ilog2(POLLERR)] = {
+		.name = "EPOLLERR",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	/* 0x0010 */
+	[ilog2(POLLHUP)] = {
+		.name = "EPOLLHUP",
+		.type = __type_integer(int, 1, 1, 0, __LITTLE_ENDIAN, 10, none),
+	},
+	[ilog2(LTTNG_EPOLL_NRFLAGS)] = {
+		.name = "padding",
+		.type = __type_integer(int, EPOLL_FLAGS_PADDING_SIZE, 1, 0,
+				__LITTLE_ENDIAN, 10, none),
+	},
+
+};
+
+static struct lttng_event_field lttng_epoll_data_fields[] = {
+	[0] = {
+		.name = "u64",
+		.type = __type_integer(uint64_t, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[1] = {
+		.name = "fd",
+		.type = __type_integer(int, 0, 0, 0, __BYTE_ORDER, 10, none),
+	},
+};
+
+static struct lttng_event_field epoll_ctl_fields[] = {
+	[0] = {
+		.name = "data_union",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
+			.u._struct.fields = lttng_epoll_data_fields,
+		}
+	},
+	[1] = {
+		.name = "raw_events",
+		.type = __type_integer(uint32_t, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[2] = {
+		.name = "events",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
+			.u._struct.fields = lttng_epoll_ctl_events_fields,
+		}
+	},
+};
+#endif /* ONCE_LTTNG_TRACE_EPOLL_CTL_H */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64)

|| defined(CONFIG_ARM)

instrumentation/syscalls/headers/syscalls_pointers_override.h +26 -0
+#define OVERRIDE_32_epoll_ctl
+#define OVERRIDE_64_epoll_ctl
+SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl,
+	TP_PROTO(sc_exit(long ret,) int epfd, int op, int fd,
+		struct epoll_event __user * uevent),
+	TP_ARGS(sc_exit(ret,) epfd, op, fd, uevent),
+	TP_locvar(
+		struct epoll_event event;
+		int err;
+	),
+	TP_code_pre(
+		tp_locvar->err = lib_ring_buffer_copy_from_user_check_nofault(
+			&tp_locvar->event, uevent, sizeof(struct epoll_event));
+		),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, epfd, epfd))
+		sc_in(ctf_enum(lttng_epoll_op, int, op_enum, op))
+		sc_in(ctf_integer(int, fd, fd))
+		sc_in(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_struct,
+					.u._struct.nr_fields = ARRAY_SIZE(epoll_ctl_fields),
+					.u._struct.fields = epoll_ctl_fields,
+				),

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+				event,
+				ctf_custom_code(
+					ctf_align(uint64_t)
+					if (!tp_locvar->err) {
+						ctf_integer_type(uint64_t, tp_locvar->event.data)
+						ctf_integer_type(int, tp_locvar->event.data)
+						ctf_integer_bitfield_type(uint32_t,
+							cpu_to_le32(tp_locvar->event.events))
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) cpu_to_le32(tp_locvar->event.events))

remove cpu_to_le32.

Thanks,

Mathieu

Quoted 18 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +13 -0
+					} else {
+						ctf_integer_type(uint64_t, 0)
+						ctf_integer_type(int, 0)
+						ctf_integer_bitfield_type(uint32_t, 0)
+						ctf_integer_bitfield_type(uint8_t, 0)
+					}
+				)
+			)
+		)
+	),
+	TP_code_post()
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
#endif /* CREATE_SYSCALL_TABLE */
--
1.9.1

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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

#16 lore raw

Re: [PATCH lttng-modules v5 5/5] Extract the payload of epoll_wait/epoll_pwait

Quoted 61 lines · ----- On Apr 22, 2016, at 8:16 PM, Julien Desfossez [email protected]…

When epoll_wait returns, extract the content of the "events" field (events set and data payload).

Here is an example output:
syscall_entry_epoll_wait: { epfd = 3, maxevents = 32, timeout = 100 }
syscall_exit_epoll_wait: { ret = 1, fds_length = 1,
fds = [ [0] = { raw_events = 0x1,
events = { EPOLLIN = 1, EPOLLPRI = 0, EPOLLOUT = 0, EPOLLERR = 0,

     padding = 0 },

data_union = { u64 = 0x100000005, fd = 5 } } ]
}

---
.../syscalls/headers/syscalls_pointers_override.h | 234 +++++++++++++++++++++

1 file changed, 234 insertions(+)
instrumentation/syscalls/headers/syscalls_pointers_override.h +0 -0
index 9fe0030..68ba1a2 100644
@@ -1062,4 +1062,238 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_ctl,
 )
 #endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */

instrumentation/syscalls/headers/syscalls_pointers_override.h +34 -0
+#ifndef ONCE_LTTNG_TRACE_EPOLL_H
+#define ONCE_LTTNG_TRACE_EPOLL_H
+
+static struct lttng_event_field lttng_epoll_wait_fields[] = {
+	[0] = {
+		.name = "data_union",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_data_fields),
+			.u._struct.fields = lttng_epoll_data_fields,
+		}
+	},
+	[1] = {
+		.name = "raw_events",
+		.type = __type_integer(uint32_t, 0, 0, 0, __BYTE_ORDER, 16, none),
+	},
+	[2] = {
+		.name = "events",
+		.type = {
+			.atype = atype_struct,
+			.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_ctl_events_fields),
+			.u._struct.fields = lttng_epoll_ctl_events_fields,
+		}
+	},
+};
+
+static struct lttng_type lttng_epoll_wait_elem = {
+	.atype = atype_struct,
+	.u._struct.nr_fields = ARRAY_SIZE(lttng_epoll_wait_fields),
+	.u._struct.fields = lttng_epoll_wait_fields,
+};
+
+#endif /* ONCE_LTTNG_TRACE_EPOLL_H */
+

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
+#define OVERRIDE_32_epoll_wait
+#define OVERRIDE_64_epoll_wait
+SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_wait,
+	TP_PROTO(sc_exit(long ret,) int epfd, struct epoll_event __user * uevents,
+		int maxevents, int timeout),
+	TP_ARGS(sc_exit(ret,) epfd, uevents, maxevents, timeout),
+	TP_locvar(
+		sc_out(
+			unsigned int fds_length, overflow;

uint8_t for overflow.

Quoted 20 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +20 -0
+			struct epoll_event *events;
+		)
+	),
+	TP_code_pre(
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_epoll_ctl_events_fields) - 1) +
+				EPOLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		sc_out({
+			int err;
+			unsigned long maxalloc;
+
+			tp_locvar->fds_length = 0;
+			tp_locvar->events = NULL;
+			tp_locvar->overflow = 0;
+
+			if (maxevents <= 0 || ret <= 0 || ret > maxevents)
+				goto skip_code;
+
+			if ((maxevents * sizeof(struct epoll_event)) > PAGE_SIZE) {
+				maxalloc = PAGE_SIZE / sizeof(struct epoll_event);

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+				if (ret > maxalloc) {
+					tp_locvar->fds_length = maxalloc;
+					tp_locvar->overflow = 1;
+				} else {
+					tp_locvar->fds_length = ret;
+				}
+			} else {
+				maxalloc = maxevents;
+				tp_locvar->fds_length = ret;
+			}

if ((maxevents * sizeof(struct epoll_event)) > PAGE_SIZE) {
maxalloc = PAGE_SIZE / sizeof(struct epoll_event);
} else {
maxalloc = maxevents;
}

if (ret > maxalloc) {
tp_locvar->fds_length = maxalloc;
tp_locvar->overflow = 1;
} else {
tp_locvar->fds_length = ret;
}

Quoted 4 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +4 -0
+
+			tp_locvar->events = kmalloc(
+				maxalloc * sizeof(struct epoll_event),
+				GFP_ATOMIC);

.........

Quoted 11 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +11 -0
+			if (!tp_locvar->events) {
+				tp_locvar->fds_length = 0;
+				goto skip_code;
+			}
+
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->events, uevents,
+				maxevents * sizeof(struct epoll_event));
+			if (err != 0)
+				tp_locvar->fds_length = 0;
+		}

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, epfd, epfd))
+		sc_in(ctf_integer(int, maxevents, maxevents))
+		sc_in(ctf_integer(int, timeout, timeout))
+		sc_out(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_out(ctf_integer(int, overflow, tp_locvar->overflow))

uint8_t

Quoted 11 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +11 -0
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name =
+						"fds_length",
+					.u.sequence_compound.elem_type =
+						&lttng_epoll_wait_elem,
+				),
+				fds,
+				ctf_custom_code(

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+					uint32_t i;
+
+					ctf_align(uint64_t)
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(uint64_t, tp_locvar->events[i].data)
+						ctf_integer_type(int, tp_locvar->events[i].data)
+						ctf_integer_bitfield_type(uint32_t,
+							cpu_to_le32(tp_locvar->events[i].events))
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) cpu_to_le32(tp_locvar->events[i].events))

remove cpu_to_le32.

Quoted 15 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +14 -0
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		sc_out(
+			kfree(tp_locvar->events);
+		)
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64)

|| defined(CONFIG_ARM)

instrumentation/syscalls/headers/syscalls_pointers_override.h

Quoted 10 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +10 -0
+#define OVERRIDE_32_epoll_pwait
+#define OVERRIDE_64_epoll_pwait
+SC_LTTNG_TRACEPOINT_EVENT_CODE(epoll_pwait,
+	TP_PROTO(sc_exit(long ret,) int epfd, struct epoll_event __user * uevents,
+		int maxevents, int timeout, const sigset_t * sigmask, size_t sigsetsize),
+	TP_ARGS(sc_exit(ret,) epfd, uevents, maxevents, timeout, sigmask, sigsetsize),
+	TP_locvar(
+		sc_out(
+			unsigned int fds_length, overflow;
+			struct epoll_event *events;

use macros to remove code duplication.

Thanks,

Mathieu

Quoted 94 lines
instrumentation/syscalls/headers/syscalls_pointers_override.h +89 -0
+		)
+	),
+	TP_code_pre(
+		BUILD_BUG_ON(((ARRAY_SIZE(lttng_epoll_ctl_events_fields) - 1) +
+				EPOLL_FLAGS_PADDING_SIZE) !=
+					sizeof(uint8_t) * BITS_PER_BYTE);
+		sc_out({
+			int err;
+			unsigned long maxalloc;
+
+			tp_locvar->fds_length = 0;
+			tp_locvar->events = NULL;
+			tp_locvar->overflow = 0;
+
+			if (maxevents <= 0 || ret <= 0 || ret > maxevents)
+				goto skip_code;
+
+			if ((maxevents * sizeof(struct epoll_event)) > PAGE_SIZE) {
+				maxalloc = PAGE_SIZE / sizeof(struct epoll_event);
+				if (ret > maxalloc) {
+					tp_locvar->fds_length = maxalloc;
+					tp_locvar->overflow = 1;
+				} else {
+					tp_locvar->fds_length = ret;
+				}
+			} else {
+				maxalloc = maxevents;
+				tp_locvar->fds_length = ret;
+			}
+
+			tp_locvar->events = kmalloc(
+				maxalloc * sizeof(struct epoll_event),
+				GFP_ATOMIC);
+			if (!tp_locvar->events) {
+				tp_locvar->fds_length = 0;
+				goto skip_code;
+			}
+
+			err = lib_ring_buffer_copy_from_user_check_nofault(
+				tp_locvar->events, uevents,
+				maxevents * sizeof(struct epoll_event));
+			if (err != 0)
+				tp_locvar->fds_length = 0;
+		}
+		skip_code:
+		)
+	),
+	TP_FIELDS(
+		sc_exit(ctf_integer(long, ret, ret))
+		sc_in(ctf_integer(int, epfd, epfd))
+		sc_in(ctf_integer(int, maxevents, maxevents))
+		sc_in(ctf_integer(int, timeout, timeout))
+		sc_in(ctf_integer(const sigset_t *, sigmask, sigmask))
+		sc_in(ctf_integer(size_t, sigsetsize, sigsetsize))
+		sc_out(ctf_integer(unsigned int, fds_length, tp_locvar->fds_length))
+		sc_out(ctf_integer(int, overflow, tp_locvar->overflow))
+		sc_out(
+			ctf_custom_field(
+				ctf_custom_type(
+					.atype = atype_sequence_compound,
+					.u.sequence_compound.length_name =
+						"fds_length",
+					.u.sequence_compound.elem_type =
+						&lttng_epoll_wait_elem,
+				),
+				fds,
+				ctf_custom_code(
+					uint32_t i;
+
+					ctf_align(uint64_t)
+					for (i = 0; i < tp_locvar->fds_length; i++) {
+						ctf_integer_type(uint64_t, tp_locvar->events[i].data)
+						ctf_integer_type(int, tp_locvar->events[i].data)
+						ctf_integer_bitfield_type(uint32_t,
+							cpu_to_le32(tp_locvar->events[i].events))
+						ctf_integer_bitfield_type(uint8_t,
+							(uint8_t) cpu_to_le32(tp_locvar->events[i].events))
+					}
+				)
+			)
+		)
+	),
+	TP_code_post(
+		sc_out(
+			kfree(tp_locvar->events);
+		)
+	)
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||

defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
#endif /* CREATE_SYSCALL_TABLE */
--
1.9.1

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev