Bug 383901 - PTP_ENABLE_PPS ioctl
Summary: PTP_ENABLE_PPS ioctl
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-23 10:09 UTC by Thomas Calvert
Modified: 2019-06-26 11:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Inhibit grumble on PTP_ENABLE_PPS ioctl (5.23 KB, patch)
2017-08-23 10:09 UTC, Thomas Calvert
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Calvert 2017-08-23 10:09:45 UTC
Created attachment 107471 [details]
Inhibit grumble on PTP_ENABLE_PPS ioctl

Attached patch makes valgrind ignore ARG3 for the PTP_ENABLE_PPS ioctl. This ioctl takes a bool by value, and by default valgrind tries to interpret it as a pointer which produces noise in its output.

   https://github.com/torvalds/linux/blob/master/drivers/ptp/ptp_chardev.c#L179
Comment 1 Thomas Calvert 2017-08-23 10:40:19 UTC
Comment on attachment 107471 [details]
Inhibit grumble on PTP_ENABLE_PPS ioctl

>commit bccbf131551193e6af88dba1866f4404e2cd61ac
>Author: Thomas Calvert
>Date:   Tue Aug 22 18:18:48 2017 +0100
>
>    Add PTP_ENABLE_PPS ioctl
>
>diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
>index 4120c1d..3b64d69 100644
>--- a/coregrind/m_syswrap/syswrap-linux.c
>+++ b/coregrind/m_syswrap/syswrap-linux.c
>@@ -9025,6 +9025,10 @@ PRE(sys_ioctl)
>       PRE_MEM_WRITE("ioctl(VKI_PERF_EVENT_IOC_ID)", (Addr)ARG3, sizeof(__vki_u64));
>       break;
> 
>+   case VKI_PTP_ENABLE_PPS:
>+      /* Takes a bool by value (0/1) */
>+      break;
>+
>    default:
>       /* EVIOC* are variable length and return size written on success */
>       switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) {
>@@ -10954,6 +10958,10 @@ POST(sys_ioctl)
>       POST_MEM_WRITE((Addr)ARG3, sizeof(__vki_u64));
>       break;
> 
>+   case VKI_PTP_ENABLE_PPS:
>+      /* Takes a bool by value (0/1) */
>+      break;
>+
>    default:
>       /* EVIOC* are variable length and return size written on success */
>       switch (ARG2 & ~(_VKI_IOC_SIZEMASK << _VKI_IOC_SIZESHIFT)) {
>diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h
>index 4840a53..a63396e 100644
>--- a/include/vki/vki-linux.h
>+++ b/include/vki/vki-linux.h
>@@ -4750,6 +4750,114 @@ struct vki_serial_struct {
> 
> #endif // __VKI_LINUX_H
> 
>+//----------------------------------------------------------------------
>+// From linux-4.0/include/uapi/linux/ptp_clock.h
>+//----------------------------------------------------------------------
>+
>+/*
>+ * struct vki_ptp_clock_time - represents a time value
>+ *
>+ * The sign of the seconds field applies to the whole value. The
>+ * nanoseconds field is always unsigned. The reserved field is
>+ * included for sub-nanosecond resolution, should the demand for
>+ * this ever appear.
>+ *
>+ */
>+struct vki_ptp_clock_time {
>+	__vki_s64 sec;  /* seconds */
>+	__vki_u32 nsec; /* nanoseconds */
>+	__vki_u32 reserved;
>+};
>+
>+struct vki_ptp_clock_caps {
>+	int max_adj;   /* Maximum frequency adjustment in parts per billon. */
>+	int n_alarm;   /* Number of programmable alarms. */
>+	int n_ext_ts;  /* Number of external time stamp channels. */
>+	int n_per_out; /* Number of programmable periodic signals. */
>+	int pps;       /* Whether the clock supports a PPS callback. */
>+	int n_pins;    /* Number of input/output pins. */
>+	/* Whether the clock supports precise system-device cross timestamps */
>+	int cross_timestamping;
>+	int rsv[13];   /* Reserved for future use. */
>+};
>+
>+struct vki_ptp_extts_request {
>+	unsigned int index;  /* Which channel to configure. */
>+	unsigned int flags;  /* Bit field for PTP_xxx flags. */
>+	unsigned int rsv[2]; /* Reserved for future use. */
>+};
>+
>+struct vki_ptp_perout_request {
>+	struct vki_ptp_clock_time start;  /* Absolute start time. */
>+	struct vki_ptp_clock_time period; /* Desired period, zero means disable. */
>+	unsigned int index;           /* Which channel to configure. */
>+	unsigned int flags;           /* Reserved for future use. */
>+	unsigned int rsv[4];          /* Reserved for future use. */
>+};
>+
>+#define PTP_MAX_SAMPLES 25 /* Maximum allowed offset measurement samples. */
>+
>+struct vki_ptp_sys_offset {
>+	unsigned int n_samples; /* Desired number of measurements. */
>+	unsigned int rsv[3];    /* Reserved for future use. */
>+	/*
>+	 * Array of interleaved system/phc time stamps. The kernel
>+	 * will provide 2*n_samples + 1 time stamps, with the last
>+	 * one as a system time stamp.
>+	 */
>+	struct vki_ptp_clock_time ts[2 * PTP_MAX_SAMPLES + 1];
>+};
>+
>+struct vki_ptp_sys_offset_precise {
>+	struct vki_ptp_clock_time device;
>+	struct vki_ptp_clock_time sys_realtime;
>+	struct vki_ptp_clock_time sys_monoraw;
>+	unsigned int rsv[4];    /* Reserved for future use. */
>+};
>+
>+enum vki_ptp_pin_function {
>+	PTP_PF_NONE,
>+	PTP_PF_EXTTS,
>+	PTP_PF_PEROUT,
>+	PTP_PF_PHYSYNC,
>+};
>+
>+struct ptp_pin_desc {
>+	/*
>+	 * Hardware specific human readable pin name. This field is
>+	 * set by the kernel during the PTP_PIN_GETFUNC ioctl and is
>+	 * ignored for the PTP_PIN_SETFUNC ioctl.
>+	 */
>+	char name[64];
>+	/*
>+	 * Pin index in the range of zero to ptp_clock_caps.n_pins - 1.
>+	 */
>+	unsigned int index;
>+	/*
>+	 * Which of the PTP_PF_xxx functions to use on this pin.
>+	 */
>+	unsigned int func;
>+	/*
>+	 * The specific channel to use for this function.
>+	 * This corresponds to the 'index' field of the
>+	 * PTP_EXTTS_REQUEST and PTP_PEROUT_REQUEST ioctls.
>+	 */
>+	unsigned int chan;
>+	/*
>+	 * Reserved for future use.
>+	 */
>+	unsigned int rsv[5];
>+};
>+
>+#define VKI_PTP_CLOCK_GETCAPS		_VKI_IOW('=', 1, struct vki_ptp_clock_caps)
>+#define VKI_PTP_EXTTS_REQUEST		_VKI_IOW('=', 2, struct vki_ptp_extts_request)
>+#define VKI_PTP_PEROUT_REQUEST		_VKI_IOW('=', 3, struct vki_ptp_perout_request)
>+#define VKI_PTP_ENABLE_PPS		_VKI_IOW('=', 4, int)
>+#define VKI_PTP_SYS_OFFSET		_VKI_IOW('=', 5, struct vki_ptp_sys_offset)
>+#define VKI_PTP_PIN_GETFUNC		_VKI_IOW('=', 6, struct vki_ptp_pin_desc)
>+#define VKI_PTP_PIN_SETFUNC		_VKI_IOW('=', 7, struct vki_ptp_pin_desc)
>+#define VKI_PTP_SYS_OFFSET_PRECISE	_VKI_IOW('=', 8, struct vki_ptp_sys_offset_precise)
>+
> /*--------------------------------------------------------------------*/
> /*--- end                                                          ---*/
> /*--------------------------------------------------------------------*/
Comment 2 Miroslav Lichvar 2019-06-26 11:34:50 UTC
FWIW, I've submitted a patch adding a complete support for PTP ioctls in bug #409206. It does the same thing for the PTP_ENABLE_PPS ioctl as this patch.