Uploaded image for project: 'Lustre'
  1. Lustre
  2. LU-18069

Incorrect timespec64_to_ns() in sles15sp5 kernel

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Minor
    • None
    • None
    • None
    • 3
    • 9223372036854775807

    Description

      This bug causes sanity/39m fails in LU-1158, which tries to support nanosecond timestamps.

      Wrong version of timespec64_to_ns() function in sles15sp5 (in time64.h):

      #define KTIME_MAX                       ((s64)~((u64)1 << 63))
      #define KTIME_SEC_MAX                   (KTIME_MAX / NSEC_PER_SEC)
      
      static inline s64 timespec64_to_ns(const struct timespec64 *ts)
      {
              /* Prevent multiplication overflow */
              if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX)
                      return KTIME_MAX;
              return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
      }
      

      If tv_sec is a negative value, it always returns KTIME_MAX. Then sanity/test_39m fails.

      Correct version of timespec64_to_ns() in rocky 8.9:

      #define KTIME_MAX                       ((s64)~((u64)1 << 63))
      #define KTIME_MIN                       (-KTIME_MAX - 1)
      #define KTIME_SEC_MAX                   (KTIME_MAX / NSEC_PER_SEC)
      #define KTIME_SEC_MIN                   (KTIME_MIN / NSEC_PER_SEC)
      
      static inline s64 timespec64_to_ns(const struct timespec64 *ts)
      {
              /* Prevent multiplication overflow / underflow */
              if (ts->tv_sec >= KTIME_SEC_MAX)
                      return KTIME_MAX;
      
              if (ts->tv_sec <= KTIME_SEC_MIN)
                      return KTIME_MIN;
      
              return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
      }
      

      This version can handle negative tv_sec correctly.

      Attachments

        Issue Links

          Activity

            People

              wc-triage WC Triage
              flei Feng Lei
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: