06 Aug, 2020

1 commit

  • The way we define the phase (the difference between the time of the
    signal's rising edge, and the closest integer multiple of the period),
    it doesn't make sense to have a phase value equal or larger than 1
    period.

    So deny these settings coming from the user.

    Signed-off-by: Vladimir Oltean
    Acked-by: Richard Cochran
    Acked-by: Jacob Keller
    Signed-off-by: David S. Miller

    Vladimir Oltean
     

20 Jul, 2020

1 commit

  • There are external event timestampers (PHCs with support for
    PTP_EXTTS_REQUEST) that timestamp both event edges.

    When those edges are very close (such as in the case of a short pulse),
    there is a chance that the collected timestamp might be of the rising,
    or of the falling edge, we never know.

    There are also PHCs capable of generating periodic output with a
    configurable duty cycle. This is good news, because we can space the
    rising and falling edge out enough in time, that the risks to overrun
    the 1-entry timestamp FIFO of the extts PHC are lower (example: the
    perout PHC can be configured for a period of 1 second, and an "on" time
    of 0.5 seconds, resulting in a duty cycle of 50%).

    A flag is introduced for signaling that an on time is present in the
    perout request structure, for preserving compatibility. Logically
    speaking, the duty cycle cannot exceed 100% and the PTP core checks for
    this.

    PHC drivers that don't support this flag emit a periodic output of an
    unspecified duty cycle, same as before.

    The duty cycle is encoded as an "on" time, similar to the "start" and
    "period" times, and reuses the reserved space while preserving overall
    binary layout.

    Pahole reported before:

    struct ptp_perout_request {
    struct ptp_clock_time start; /* 0 16 */
    struct ptp_clock_time period; /* 16 16 */
    unsigned int index; /* 32 4 */
    unsigned int flags; /* 36 4 */
    unsigned int rsv[4]; /* 40 16 */

    /* size: 56, cachelines: 1, members: 5 */
    /* last cacheline: 56 bytes */
    };

    And now:

    struct ptp_perout_request {
    struct ptp_clock_time start; /* 0 16 */
    struct ptp_clock_time period; /* 16 16 */
    unsigned int index; /* 32 4 */
    unsigned int flags; /* 36 4 */
    union {
    struct ptp_clock_time on; /* 40 16 */
    unsigned int rsv[4]; /* 40 16 */
    }; /* 40 16 */

    /* size: 56, cachelines: 1, members: 5 */
    /* last cacheline: 56 bytes */
    };

    Signed-off-by: Vladimir Oltean
    Signed-off-by: David S. Miller

    Vladimir Oltean
     

03 May, 2020

1 commit


31 Mar, 2020

1 commit

  • The PTP Hardware Clock (PHC) subsystem offers an API for configuring
    programmable pins. User space sets or gets the settings using ioctls,
    and drivers verify dialed settings via a callback. Drivers may also
    query pin settings by calling the ptp_find_pin() method.

    Although the core subsystem protects concurrent access to the pin
    settings, the implementation places illogical restrictions on how
    drivers may call ptp_find_pin(). When enabling an auxiliary function
    via the .enable(on=1) callback, drivers may invoke the pin finding
    method, but when disabling with .enable(on=0) drivers are not
    permitted to do so. With the exception of the mv88e6xxx, all of the
    PHC drivers do respect this restriction, but still the locking pattern
    is both confusing and unnecessary.

    This patch changes the locking implementation to allow PHC drivers to
    freely call ptp_find_pin() from their .enable() and .verify()
    callbacks.

    V2 ChangeLog:
    - fixed spelling in the kernel doc
    - add Vladimir's tested by tag

    Signed-off-by: Richard Cochran
    Reported-by: Yangbo Lu
    Tested-by: Vladimir Oltean
    Signed-off-by: David S. Miller

    Richard Cochran
     

16 Nov, 2019

2 commits


28 Sep, 2019

1 commit

  • Commit 415606588c61 ("PTP: introduce new versions of IOCTLs",
    2019-09-13) introduced new versions of the PTP ioctls which actually
    validate that the flags are acceptable values.

    As part of this, it cleared the flags value using a bitwise
    and+negation, in an attempt to prevent the old ioctl from accidentally
    enabling new features.

    This is incorrect for a couple of reasons. First, it results in
    accidentally preventing previously working flags on the request ioctl.
    By clearing the "valid" flags, we now no longer allow setting the
    enable, rising edge, or falling edge flags.

    Second, if we add new additional flags in the future, they must not be
    set by the old ioctl. (Since the flag wasn't checked before, we could
    potentially break userspace programs which sent garbage flag data.

    The correct way to resolve this is to check for and clear all but the
    originally valid flags.

    Create defines indicating which flags are correctly checked and
    interpreted by the original ioctls. Use these to clear any bits which
    will not be correctly interpreted by the original ioctls.

    In the future, new flags must be added to the VALID_FLAGS macros, but
    *not* to the V1_VALID_FLAGS macros. In this way, new features may be
    exposed over the v2 ioctls, but without breaking previous userspace
    which happened to not clear the flags value properly. The old ioctl will
    continue to behave the same way, while the new ioctl gains the benefit
    of using the flags fields.

    Cc: Richard Cochran
    Cc: Felipe Balbi
    Cc: David S. Miller
    Cc: Christopher Hall
    Signed-off-by: Jacob Keller
    Acked-by: Richard Cochran
    Signed-off-by: David S. Miller

    Jacob Keller
     

13 Sep, 2019

1 commit

  • The current version of the IOCTL have a small problem which prevents us
    from extending the API by making use of reserved fields. In these new
    IOCTLs, we are now making sure that flags and rsv fields are zero which
    will allow us to extend the API in the future.

    Reviewed-by: Richard Cochran
    Signed-off-by: Felipe Balbi
    Signed-off-by: David S. Miller

    Felipe Balbi
     

24 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details you
    should have received a copy of the gnu general public license along
    with this program if not write to the free software foundation inc
    675 mass ave cambridge ma 02139 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 441 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Michael Ellerman (powerpc)
    Reviewed-by: Richard Fontana
    Reviewed-by: Allison Randal
    Reviewed-by: Kate Stewart
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190520071858.739733335@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

09 Jan, 2019

1 commit


10 Nov, 2018

4 commits

  • When a driver provides gettimex64(), use it in the PTP_SYS_OFFSET ioctl
    and POSIX clock's gettime() instead of gettime64(). Drivers should
    provide only one of the functions.

    Cc: Richard Cochran
    Cc: Jacob Keller
    Signed-off-by: Miroslav Lichvar
    Signed-off-by: David S. Miller

    Miroslav Lichvar
     
  • The PTP_SYS_OFFSET ioctl, which can be used to measure the offset
    between a PHC and the system clock, includes the total time that the
    driver needs to read the PHC timestamp.

    This typically involves reading of multiple PCI registers (sometimes in
    multiple iterations) and the register that contains the lowest bits of
    the timestamp is not read in the middle between the two readings of the
    system clock. This asymmetry causes the measured offset to have a
    significant error.

    Introduce a new ioctl, driver function, and helper functions, which
    allow the reading of the lowest register to be isolated from the other
    readings in order to reduce the asymmetry. The ioctl returns three
    timestamps for each measurement:
    - system time right before reading the lowest bits of the PHC timestamp
    - PHC time
    - system time immediately after reading the lowest bits of the PHC
    timestamp

    Cc: Richard Cochran
    Cc: Jacob Keller
    Cc: Marcelo Tosatti
    Signed-off-by: Miroslav Lichvar
    Signed-off-by: David S. Miller

    Miroslav Lichvar
     
  • If a gettime64 call fails, return the error and avoid copying data back
    to user.

    Cc: Richard Cochran
    Cc: Jacob Keller
    Signed-off-by: Miroslav Lichvar
    Signed-off-by: David S. Miller

    Miroslav Lichvar
     
  • Reorder declarations of variables as reversed Christmas tree.

    Cc: Richard Cochran
    Suggested-by: Richard Cochran
    Signed-off-by: Miroslav Lichvar
    Signed-off-by: David S. Miller

    Miroslav Lichvar
     

18 Oct, 2018

1 commit

  • pin_index can be indirectly controlled by user-space, hence leading
    to a potential exploitation of the Spectre variant 1 vulnerability.

    This issue was detected with the help of Smatch:

    drivers/ptp/ptp_chardev.c:253 ptp_ioctl() warn: potential spectre issue
    'ops->pin_config' [r] (local cap)

    Fix this by sanitizing pin_index before using it to index
    ops->pin_config, and before passing it as an argument to
    function ptp_set_pinfunc(), in which it is used to index
    info->pin_config.

    Notice that given that speculation windows are large, the policy is
    to kill the speculation on the first load and not worry if it can be
    completed with a dependent load/store [1].

    [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2

    Cc: stable@vger.kernel.org
    Signed-off-by: Gustavo A. R. Silva
    Acked-by: Richard Cochran
    Signed-off-by: David S. Miller

    Gustavo A. R. Silva
     

19 Jul, 2018

1 commit

  • It seems that a *break* is missing in order to avoid falling through
    to the default case. Otherwise, checking *chan* makes no sense.

    Fixes: 72df7a7244c0 ("ptp: Allow reassigning calibration pin function")
    Signed-off-by: Gustavo A. R. Silva
    Acked-by: Richard Cochran
    Signed-off-by: David S. Miller

    Gustavo A. R. Silva
     

20 Jun, 2018

1 commit


12 Feb, 2018

1 commit

  • This is the mindless scripted replacement of kernel use of POLL*
    variables as described by Al, done by this script:

    for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
    L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
    for f in $L; do sed -i "-es/^\([^\"]*\)\(\\)/\\1E\\2/" $f; done
    done

    with de-mangling cleanups yet to come.

    NOTE! On almost all architectures, the EPOLL* constants have the same
    values as the POLL* constants do. But they keyword here is "almost".
    For various bad reasons they aren't the same, and epoll() doesn't
    actually work quite correctly in some cases due to this on Sparc et al.

    The next patch from Al will sort out the final differences, and we
    should be all done.

    Scripted-by: Al Viro
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

29 Nov, 2017

1 commit


13 Oct, 2016

1 commit


30 May, 2016

1 commit

  • If we pass ERR_PTR(-EFAULT) to kfree() then it's going to oops.

    Fixes: 2ece068e1b1d ('ptp: use memdup_user().')
    Signed-off-by: Dan Carpenter
    Acked-by: Richard Cochran
    Signed-off-by: David S. Miller

    Dan Carpenter
     

24 May, 2016

1 commit

  • Use memdup_user to duplicate a memory region from user-space to
    kernel-space, instead of open coding using kmalloc & copy_from_user.

    Signed-off-by: Muhammad Falak R Wani
    Acked-by: Richard Cochran
    Signed-off-by: David S. Miller

    Muhammad Falak R Wani
     

04 Mar, 2016

1 commit

  • Currently, network /system cross-timestamping is performed in the
    PTP_SYS_OFFSET ioctl. The PTP clock driver reads gettimeofday() and
    the gettime64() callback provided by the driver. The cross-timestamp
    is best effort where the latency between the capture of system time
    (getnstimeofday()) and the device time (driver callback) may be
    significant.

    The getcrosststamp() callback and corresponding PTP_SYS_OFFSET_PRECISE
    ioctl allows the driver to perform this device/system correlation when
    for example cross timestamp hardware is available. Modern Intel
    systems can do this for onboard Ethernet controllers using the ART
    counter. There is virtually zero latency between captures of the ART
    and network device clock.

    The capabilities ioctl (PTP_CLOCK_GETCAPS), is augmented allowing
    applications to query whether or not drivers implement the
    getcrosststamp callback, providing more precise cross timestamping.

    Cc: Prarit Bhargava
    Cc: Richard Cochran
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Andy Lutomirski
    Cc: kevin.b.stanton@intel.com
    Cc: kevin.j.clarke@intel.com
    Cc: hpa@zytor.com
    Cc: jeffrey.t.kirsher@intel.com
    Cc: netdev@vger.kernel.org
    Acked-by: Richard Cochran
    Signed-off-by: Christopher S. Hall
    [jstultz: Commit subject tweaks]
    Signed-off-by: John Stultz

    Christopher S. Hall
     

01 Apr, 2015

2 commits


02 Jul, 2014

1 commit

  • The ptp pin function programming does not allow calibration pin to change
    function. This is problematic on hardware that uses the default calibration
    pin for other purposes.

    Removing this limitation does not impact calibration if userspace does not
    reprogram the calibration pin.

    Signed-off-by: Stefan Sørensen
    Signed-off-by: David S. Miller

    Stefan Sørensen
     

22 Mar, 2014

1 commit

  • This patch adds a pair of new ioctls to the PTP Hardware Clock device
    interface. Using the ioctls, user space programs can query each pin to
    find out its current function and also reprogram a different function
    if desired.

    Signed-off-by: Richard Cochran
    Signed-off-by: David S. Miller

    Richard Cochran
     

27 Nov, 2012

2 commits


01 Nov, 2012

1 commit

  • This patch adds an ioctl for PTP Hardware Clock (PHC) devices that allows
    user space to measure the time offset between the PHC and the system
    clock. Rather than hard coding any kind of estimation algorithm into the
    kernel, this patch takes the more flexible approach of just delivering
    an array of raw clock readings. In that way, the user space clock servo
    may be adapted to new and different hardware clocks.

    Signed-off-by: Richard Cochran
    Acked-by: Jacob Keller
    Signed-off-by: David S. Miller

    Richard Cochran
     

02 Jun, 2011

2 commits


24 May, 2011

1 commit

  • This patch adds an infrastructure for hardware clocks that implement
    IEEE 1588, the Precision Time Protocol (PTP). A class driver offers a
    registration method to particular hardware clock drivers. Each clock is
    presented as a standard POSIX clock.

    The ancillary clock features are exposed in two different ways, via
    the sysfs and by a character device.

    Signed-off-by: Richard Cochran
    Acked-by: Arnd Bergmann
    Acked-by: David S. Miller
    Signed-off-by: John Stultz

    Richard Cochran