The test helps to validate clamping and mount behaviors
according to supported file system timestamp ranges.
Note that the test can fail on 32-bit systems for a
few file systems. This will be corrected when vfs is
transitioned to use 64-bit timestamps.
Signed-off-by: Deepa Dinamani <deepa.kernel(a)gmail.com>
---
The branch of the kernel tree can be located at
https://github.com/deepa-hub/vfs refs/heads/vfs_timestamp_policy
The xfs_io patch to add utimes is at
https://www.spinics.net/lists/linux-xfs/msg02952.html
Changes since v2:
* Refactored notrun handling
* Updated comments
Changes since v1:
* Use xfs_io utimes command
* Updated error handling
* Reorganized code according to review comments
common/rc | 48 +++++++++++++
tests/generic/390 | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/390.out | 2 +
tests/generic/group | 1 +
4 files changed, 243 insertions(+)
create mode 100755 tests/generic/390
create mode 100644 tests/generic/390.out
diff --git a/common/rc b/common/rc
index e3b54ec..17f025e 100644
--- a/common/rc
+++ b/common/rc
@@ -1960,6 +1960,51 @@ _run_aiodio()
return $status
}
+# this test requires y2038 sysfs switch and filesystem
+# timestamp ranges support.
+_require_y2038()
+{
+ local device=${1:-$TEST_DEV}
+ local sysfsdir=/proc/sys/fs/fs-timestamp-check-on
+
+ if [ ! -e $sysfsdir ]; then
+ _notrun "no kernel support for y2038 sysfs switch"
+ fi
+
+ local tsmin tsmax
+ read tsmin tsmax <<<$(_filesystem_timestamp_range $device)
+ if [ $tsmin -eq -1 -a $tsmax -eq -1 ]; then
+ _notrun "filesystem $FSTYP timestamp bounds are unknown"
+ fi
+}
+
+_filesystem_timestamp_range()
+{
+ device=${1:-$TEST_DEV}
+ case $FSTYP in
+ ext4)
+ if [ $(dumpe2fs -h $device 2>/dev/null | grep "Inode size:" | cut -d: -f2) -gt 128 ]; then
+ echo "-2147483648 15032385535"
+ else
+ echo "-2147483648 2147483647"
+ fi
+ ;;
+
+ xfs)
+ echo "-2147483648 2147483647"
+ ;;
+ jfs)
+ echo "0 4294967295"
+ ;;
+ f2fs)
+ echo "-2147483648 2147483647"
+ ;;
+ *)
+ echo "-1 -1"
+ ;;
+ esac
+}
+
# indicate whether YP/NIS is active or not
#
_yp_active()
@@ -2070,6 +2115,9 @@ _require_xfs_io_command()
echo $testio | egrep -q "Inappropriate ioctl" && \
_notrun "xfs_io $command support is missing"
;;
+ "utimes" )
+ testio=`$XFS_IO_PROG -f -c "utimes" 0 0 0 0 $testfile 2>&1`
+ ;;
*)
testio=`$XFS_IO_PROG -c "$command help" 2>&1`
esac
diff --git a/tests/generic/390 b/tests/generic/390
new file mode 100755
index 0000000..f68b931
--- /dev/null
+++ b/tests/generic/390
@@ -0,0 +1,192 @@
+#! /bin/bash
+# FS QA Test 390
+#
+# Tests to verify policy for filesystem timestamps for
+# supported ranges:
+# 1. Verify filesystem rw mount according to sysctl
+# timestamp_supported.
+# 2. Verify timestamp clamping for timestamps beyond max
+# timestamp supported.
+#
+# Exit status 1: either or both tests above fail.
+# Exit status 0: both the above tests pass.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Deepa Dinamani. All Rights Reserved.
+#
+# 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.
+#
+# This program is distributed in the hope that it would 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 the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "exit \$status" 0 1 2 3 15
+
+# Get standard environment, filters and checks.
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# Prerequisites for the test run.
+_supported_fs generic
+_supported_os Linux
+_require_scratch
+_require_xfs_io_command utimes
+
+# Compare file timestamps obtained from stat
+# with a given timestamp.
+check_stat()
+{
+ file=$1
+ timestamp=$2
+
+ stat_timestamp=`stat -c"%X;%Y" $file`
+
+ prev_timestamp="$timestamp;$timestamp"
+ if [ $prev_timestamp != $stat_timestamp ]; then
+ echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
+ fi
+}
+
+run_test_individual()
+{
+ file=$1
+ timestamp=$2
+ update_time=$3
+
+ #check if the time needs update
+ if [ $update_time -eq 1 ]; then
+ echo "Updating file: $file to timestamp `date -d @$timestamp`" >> $seqres.full
+ $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
+ if [ $? -ne 0 ]; then
+ echo "Failed to update times on $file" | tee -a $seqres.full
+ fi
+ fi
+
+ tsclamp=$(($timestamp>$tsmax?$tsmax:$timestamp))
+ echo "Checking file: $file Updated timestamp is `date -d @$tsclamp`" >> $seqres.full
+ check_stat $file $tsclamp
+}
+
+run_test()
+{
+ update_time=$1
+
+ n=1
+
+ for TIME in "${TIMESTAMPS[@]}"
+ do
+ #Run the test
+ run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
+
+ #update iterator
+ ((n++))
+ done
+}
+
+_scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
+_require_y2038 $SCRATCH_DEV
+
+read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
+echo min supported timestamp $tsmin $(date --date=@$tsmin) >> $seqres.full
+echo max supported timestamp $tsmax $(date --date=@$tsmax) >> $seqres.full
+
+# Test timestamps array
+
+declare -a TIMESTAMPS=(
+ $tsmin
+ 0
+ $tsmax
+ $((tsmax+1))
+ 4294967295
+ 8589934591
+ 34359738367
+)
+
+# Max timestamp is hardcoded to Mon Jan 18 19:14:07 PST 2038
+sys_tsmax=2147483647
+echo "max timestamp that needs to be supported by fs for rw mount is" \
+ "$((sys_tsmax+1)) $(date --date=@$((sys_tsmax+1)))" >> $seqres.full
+
+read ts_check <<<$(cat /proc/sys/fs/fs-timestamp-check-on)
+
+_scratch_mount
+result=$?
+
+if [ $ts_check -ne 0 ]; then
+ echo "sysctl filesystem timestamp check is on" >> $seqres.full
+ # check for mount failure if the minimum requirement for max timestamp
+ # supported is not met.
+ if [ $sys_tsmax -ge $tsmax ]; then
+ if [ $result -eq 0 ]; then
+ echo "mount test failed" | tee -a $seqres.full
+ exit
+ fi
+ else
+ if [ $result -ne 0 ]; then
+ echo "failed to mount $SCRATCH_DEV" | tee -a $seqres.full
+ exit
+ fi
+ fi
+else
+ # if sysctl switch is off then mount should succeed always.
+ echo "sysctl filesystem timestamp check is off" >> $seqres.full
+ if [ $result -ne 0 ]; then
+ echo "failed to mount $SCRATCH_DEV and timestamp check is off" >> $seqres.full
+ exit
+ fi
+fi
+
+# Begin test case 1
+echo "In memory timestamps update test start" >> $seqres.full
+
+# update time on the file
+update_time=1
+
+run_test $update_time
+
+echo "In memory timestamps update complete" >> $seqres.full
+
+echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
+
+# unmount and remount $SCRATCH_DEV
+_scratch_cycle_mount
+
+# Begin test case 2
+
+n=1
+
+# Do not update time on the file this time, just read from disk
+update_time=0
+
+echo "On disk timestamps update test start" >> $seqres.full
+
+# Re-run test
+run_test $update_time
+
+echo "On disk timestamps update test complete" >> $seqres.full
+
+echo "y2038 inode timestamp tests completed successfully"
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/390.out b/tests/generic/390.out
new file mode 100644
index 0000000..82bd4eb
--- /dev/null
+++ b/tests/generic/390.out
@@ -0,0 +1,2 @@
+QA output created by 390
+y2038 inode timestamp tests completed successfully
diff --git a/tests/generic/group b/tests/generic/group
index 08007d7..d137d01 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -392,3 +392,4 @@
387 auto clone
388 auto log metadata
389 auto quick acl
+390 auto quick rw
--
2.7.4
The series is a preparation series for individual architectures
to use 64 bit time_t syscalls in compat and 32 bit emulation modes.
This is a follow up to the series Arnd Bergmann posted:
https://sourceware.org/ml/libc-alpha/2015-05/msg00070.html [1]
Big picture is as per the lwn article:
https://lwn.net/Articles/643234/ [2]
The series is directed at converting posix clock syscalls:
clock_gettime, clock_settime, clock_getres and clock_nanosleep
to use a new data structure __kernel_timespec at syscall boundaries.
__kernel_timespec maintains 64 bit time_t across all execution modes.
vdso will be handled as part of each architecture when they enable
support for 64 bit time_t.
The compat syscalls are repurposed to provide backward compatibility
by using them as native syscalls as well for 32 bit architectures.
They will continue to use timespec at syscall boundaries.
CONFIG_64_BIT_TIME controls whether the syscalls use __kernel_timespec
or timespec at syscall boundaries.
The series does the following:
1. Enable compat syscalls on 32 bit architectures.
2. Add a new __kernel_timespec type to be used as the data structure
for all the new syscalls.
3. Add new config CONFIG_64BIT_TIME(intead of the CONFIG_COMPAT_TIME in
[1] and [2] to switch to new definition of __kernel_timespec. It is
the same as struct timespec otherwise.
4. Add new CONFIG_32BIT_TIME to conditionally compile compat syscalls.
* Changes since v1:
* Introduce CONFIG_32BIT_TIME
* Fixed zeroing out of higher order bits of tv_nsec
* Included Arnd's changes to fix up use of compat headers
I decided against using LEGACY_TIME_SYSCALLS to conditionally compile
legacy time syscalls such as sys_nanosleep because this will need to
enclose compat_sys_nanosleep as well. So, defining it as
config LEGACY_TIME_SYSCALLS
def_bool 64BIT || !64BIT_TIME
will not include compat_sys_nanosleep. We will instead need a new config to
exclusively mark legacy syscalls.
Deepa Dinamani (10):
compat: Make compat helpers independent of CONFIG_COMPAT
include: Move compat_timespec/ timeval to compat_time.h
compat: enable compat_get/put_timespec64 always
arch: introduce CONFIG_64BIT_TIME
arch: Introduce CONFIG_COMPAT_32BIT_TIME
posix-clocks: Make compat syscalls depend on CONFIG_COMPAT_32BIT_TIME
include: Add new y2038 safe __kernel_timespec
fix get_timespec64() for y2038 safe compat interfaces
change time types to new y2038 safe __kernel_* types
nanosleep: change time types to safe __kernel_* types
arch/Kconfig | 18 +++++++
arch/arm64/include/asm/compat.h | 11 ----
arch/arm64/include/asm/stat.h | 1 +
arch/arm64/kernel/hw_breakpoint.c | 1 -
arch/arm64/kernel/perf_regs.c | 2 +-
arch/arm64/kernel/process.c | 1 -
arch/mips/include/asm/compat.h | 11 ----
arch/mips/kernel/signal32.c | 2 +-
arch/parisc/include/asm/compat.h | 11 ----
arch/powerpc/include/asm/compat.h | 11 ----
arch/powerpc/kernel/asm-offsets.c | 2 +-
arch/powerpc/oprofile/backtrace.c | 2 +-
arch/s390/hypfs/hypfs_sprp.c | 1 -
arch/s390/include/asm/compat.h | 11 ----
arch/s390/include/asm/elf.h | 3 +-
arch/s390/kvm/priv.c | 1 -
arch/s390/pci/pci_clp.c | 1 -
arch/sparc/include/asm/compat.h | 11 ----
arch/tile/include/asm/compat.h | 11 ----
arch/x86/events/core.c | 2 +-
arch/x86/include/asm/compat.h | 11 ----
arch/x86/include/asm/ftrace.h | 2 +-
arch/x86/include/asm/sys_ia32.h | 2 +-
arch/x86/kernel/sys_x86_64.c | 2 +-
drivers/s390/block/dasd_ioctl.c | 1 -
drivers/s390/char/fs3270.c | 1 -
drivers/s390/char/sclp_ctl.c | 1 -
drivers/s390/char/vmcp.c | 1 -
drivers/s390/cio/chsc_sch.c | 1 -
drivers/s390/net/qeth_core_main.c | 2 +-
drivers/staging/pi433/pi433_if.c | 2 +-
include/linux/compat.h | 11 ++--
include/linux/compat_time.h | 23 +++++++++
include/linux/restart_block.h | 7 +--
include/linux/syscalls.h | 12 ++---
include/linux/time.h | 4 +-
include/linux/time64.h | 10 +++-
include/uapi/asm-generic/posix_types.h | 1 +
include/uapi/linux/time.h | 7 +++
kernel/Makefile | 2 +-
kernel/compat.c | 92 ++++++++++++++++++----------------
kernel/time/hrtimer.c | 10 ++--
kernel/time/posix-stubs.c | 12 +++--
kernel/time/posix-timers.c | 24 ++++++---
kernel/time/time.c | 10 +++-
45 files changed, 175 insertions(+), 190 deletions(-)
create mode 100644 include/linux/compat_time.h
base-commit: b0a84f19a5161418d4360cd57603e94ed489915e
--
2.14.1
Cc: acme(a)kernel.org
Cc: benh(a)kernel.crashing.org
Cc: borntraeger(a)de.ibm.com
Cc: catalin.marinas(a)arm.com
Cc: cmetcalf(a)mellanox.com
Cc: cohuck(a)redhat.com
Cc: davem(a)davemloft.net
Cc: deller(a)gmx.de
Cc: devel(a)driverdev.osuosl.org
Cc: gerald.schaefer(a)de.ibm.com
Cc: gregkh(a)linuxfoundation.org
Cc: heiko.carstens(a)de.ibm.com
Cc: hoeppner(a)linux.vnet.ibm.com
Cc: hpa(a)zytor.com
Cc: jejb(a)parisc-linux.org
Cc: jwi(a)linux.vnet.ibm.com
Cc: linux-api(a)vger.kernel.org
Cc: linux-arch(a)vger.kernel.org
Cc: linux-kernel(a)vger.kernel.org
Cc: linux-mips(a)linux-mips.org
Cc: linux-parisc(a)vger.kernel.org
Cc: linuxppc-dev(a)lists.ozlabs.org
Cc: linux-s390(a)vger.kernel.org
Cc: mark.rutland(a)arm.com
Cc: mingo(a)redhat.com
Cc: mpe(a)ellerman.id.au
Cc: oberpar(a)linux.vnet.ibm.com
Cc: oprofile-list(a)lists.sf.net
Cc: paulus(a)samba.org
Cc: peterz(a)infradead.org
Cc: ralf(a)linux-mips.org
Cc: rostedt(a)goodmis.org
Cc: rric(a)kernel.org
Cc: schwidefsky(a)de.ibm.com
Cc: sebott(a)linux.vnet.ibm.com
Cc: sparclinux(a)vger.kernel.org
Cc: sth(a)linux.vnet.ibm.com
Cc: ubraun(a)linux.vnet.ibm.com
Cc: will.deacon(a)arm.com
Cc: x86(a)kernel.org
There is a stale entry in i40iw_cm_tcp_context that apparently
was copied from the 'nes' driver but never used in i40iw.
I'm trying to kill off all users of timeval as part of the
y2038-safety work, so let's just remove this one.
Signed-off-by: Arnd Bergmann <arnd(a)arndb.de>
---
drivers/infiniband/hw/i40iw/i40iw_cm.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/infiniband/hw/i40iw/i40iw_cm.h b/drivers/infiniband/hw/i40iw/i40iw_cm.h
index 0d5840d2c4fc..1577608fc51a 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_cm.h
+++ b/drivers/infiniband/hw/i40iw/i40iw_cm.h
@@ -276,8 +276,6 @@ struct i40iw_cm_tcp_context {
u32 mss;
u8 snd_wscale;
u8 rcv_wscale;
-
- struct timeval sent_ts;
};
enum i40iw_cm_listener_state {
--
2.9.0
getnstimeofday() suffers from the overflow in y2038 on 32-bit
architectures and requires a conversion into the nanosecond format that
we want here.
This changes ssp_parse_dataframe() to use ktime_get_real_ns() directly,
which does not have that problem.
An open question is what time base should be used here. Normally
timestamps should use ktime_get_ns() or ktime_get_boot_ns() to read
monotonic time instead of "real" time, which suffers from time jumps
due to settimeofday() calls or leap seconds.
Signed-off-by: Arnd Bergmann <arnd(a)arndb.de>
---
drivers/iio/common/ssp_sensors/ssp_spi.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/iio/common/ssp_sensors/ssp_spi.c b/drivers/iio/common/ssp_sensors/ssp_spi.c
index 704284a475ae..2ab106bb3e03 100644
--- a/drivers/iio/common/ssp_sensors/ssp_spi.c
+++ b/drivers/iio/common/ssp_sensors/ssp_spi.c
@@ -277,12 +277,9 @@ static int ssp_handle_big_data(struct ssp_data *data, char *dataframe, int *idx)
static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
{
int idx, sd;
- struct timespec ts;
struct ssp_sensor_data *spd;
struct iio_dev **indio_devs = data->sensor_devs;
- getnstimeofday(&ts);
-
for (idx = 0; idx < len;) {
switch (dataframe[idx++]) {
case SSP_MSG2AP_INST_BYPASS_DATA:
@@ -329,7 +326,7 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len)
}
if (data->time_syncing)
- data->timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+ data->timestamp = ktime_get_real_ns();
return 0;
}
--
2.9.0
The series is a preparation series for individual architectures
to use 64 bit time_t syscalls in compat and 32 bit emulation modes.
This is a follow up to the series Arnd Bergmann posted:
https://sourceware.org/ml/libc-alpha/2015-05/msg00070.html
Big picture is as per the lwn article:
https://lwn.net/Articles/643234/
The series is directed at converting posix clock syscalls:
clock_gettime, clock_settime, clock_getres and clock_nanosleep
to use a new data structure __kernel_timespec at syscall boundaries.
__kernel_timespec maintains 64 bit time_t across all execution modes.
vdso will be handled as part of each architecture when they enable
support for 64 bit time_t.
The compat syscalls are repurposed to provide backward compatibility
by using them as native syscalls as well for 32 bit architectures.
They will continue to use timespec at syscall boundaries.
CONFIG_64_BIT_TIME controls whether the syscalls use __kernel_timespec
or timespec at syscall boundaries.
The series does the following:
1. Enable compat syscalls unconditionally.
2. Add a new __kernel_timespec type to be used as the data structure
for all the new syscalls.
3. Add new config CONFIG_64BIT_TIME(intead of the CONFIG_COMPAT_TIME in
[1] and [2] to switch to new definition of __kernel_timespec. It is
the same as struct timespec otherwise.
Arnd Bergmann (1):
y2038: introduce CONFIG_64BIT_TIME
Deepa Dinamani (8):
include: Move compat_timespec/ timeval to compat_time.h
compat: Make compat helpers independent of CONFIG_COMPAT
compat: enable compat_get/put_timespec64 always
posix-clocks: Enable compat syscalls always
include: Add new y2038 safe __kernel_timespec
fix get_timespec64() for y2038 safe compat interfaces
change time types to new y2038 safe __kernel_* types
nanosleep: change time types to safe __kernel_* types
arch/Kconfig | 11 ++++
arch/arm64/include/asm/compat.h | 11 ----
arch/arm64/include/asm/stat.h | 1 +
arch/arm64/kernel/hw_breakpoint.c | 1 -
arch/arm64/kernel/perf_regs.c | 2 +-
arch/arm64/kernel/process.c | 1 -
arch/mips/include/asm/compat.h | 11 ----
arch/mips/kernel/signal32.c | 2 +-
arch/parisc/include/asm/compat.h | 11 ----
arch/powerpc/include/asm/compat.h | 11 ----
arch/powerpc/kernel/asm-offsets.c | 2 +-
arch/powerpc/oprofile/backtrace.c | 2 +-
arch/s390/hypfs/hypfs_sprp.c | 1 -
arch/s390/include/asm/compat.h | 11 ----
arch/s390/include/asm/elf.h | 3 +-
arch/s390/kvm/priv.c | 1 -
arch/s390/pci/pci_clp.c | 1 -
arch/sparc/include/asm/compat.h | 11 ----
arch/tile/include/asm/compat.h | 11 ----
arch/x86/events/core.c | 2 +-
arch/x86/include/asm/compat.h | 11 ----
arch/x86/include/asm/ftrace.h | 2 +-
arch/x86/include/asm/sys_ia32.h | 2 +-
arch/x86/kernel/sys_x86_64.c | 2 +-
drivers/s390/block/dasd_ioctl.c | 1 -
drivers/s390/char/fs3270.c | 1 -
drivers/s390/char/sclp_ctl.c | 1 -
drivers/s390/char/vmcp.c | 1 -
drivers/s390/cio/chsc_sch.c | 1 -
drivers/s390/net/qeth_core_main.c | 2 +-
drivers/staging/pi433/pi433_if.c | 2 +-
include/linux/compat.h | 7 ++-
include/linux/compat_time.h | 23 +++++++++
include/linux/restart_block.h | 7 +--
include/linux/syscalls.h | 12 ++---
include/linux/time.h | 4 +-
include/linux/time64.h | 10 +++-
include/uapi/asm-generic/posix_types.h | 1 +
include/uapi/linux/time.h | 7 +++
kernel/Makefile | 2 +-
kernel/compat.c | 92 ++++++++++++++++++----------------
kernel/time/hrtimer.c | 7 +--
kernel/time/posix-stubs.c | 12 ++---
kernel/time/posix-timers.c | 20 ++++----
kernel/time/time.c | 10 +++-
45 files changed, 152 insertions(+), 195 deletions(-)
create mode 100644 include/linux/compat_time.h
base-commit: d9e0e63d9a6f88440eb201e1491fcf730272c706
--
2.11.0
Cc: acme(a)kernel.org
Cc: benh(a)kernel.crashing.org
Cc: borntraeger(a)de.ibm.com
Cc: catalin.marinas(a)arm.com
Cc: cmetcalf(a)mellanox.com
Cc: cohuck(a)redhat.com
Cc: davem(a)davemloft.net
Cc: deller(a)gmx.de
Cc: devel(a)driverdev.osuosl.org
Cc: gerald.schaefer(a)de.ibm.com
Cc: gregkh(a)linuxfoundation.org
Cc: heiko.carstens(a)de.ibm.com
Cc: hoeppner(a)linux.vnet.ibm.com
Cc: hpa(a)zytor.com
Cc: jejb(a)parisc-linux.org
Cc: jwi(a)linux.vnet.ibm.com
Cc: linux-api(a)vger.kernel.org
Cc: linux-arch(a)vger.kernel.org
Cc: linux-kernel(a)vger.kernel.org
Cc: linux-mips(a)linux-mips.org
Cc: linux-parisc(a)vger.kernel.org
Cc: linuxppc-dev(a)lists.ozlabs.org
Cc: linux-s390(a)vger.kernel.org
Cc: mark.rutland(a)arm.com
Cc: mingo(a)redhat.com
Cc: mpe(a)ellerman.id.au
Cc: oberpar(a)linux.vnet.ibm.com
Cc: oprofile-list(a)lists.sf.net
Cc: paulus(a)samba.org
Cc: peterz(a)infradead.org
Cc: ralf(a)linux-mips.org
Cc: rostedt(a)goodmis.org
Cc: rric(a)kernel.org
Cc: schwidefsky(a)de.ibm.com
Cc: sebott(a)linux.vnet.ibm.com
Cc: sparclinux(a)vger.kernel.org
Cc: sth(a)linux.vnet.ibm.com
Cc: ubraun(a)linux.vnet.ibm.com
Cc: will.deacon(a)arm.com
Cc: x86(a)kernel.org
kdb is the only user of the __current_kernel_time() interface, which is
not y2038 safe and should be removed at some point.
The kdb code also goes to great lengths to print the time in a
human-readable format from 'struct timespec', again using a non-y2038-safe
re-implementation of the generic time_to_tm() code.
Using __current_kernel_time() here is necessary since the regular
accessors that require a sequence lock might hang when called during the
xtime update. However, this is safe in the particular case since kdb is
only interested in the tv_sec field that is updated atomically.
In order to make this y2038-safe, I'm converting the code to the generic
time64_to_tm helper, but that introduces the problem that we have no
interface like __current_kernel_time() that provides a 64-bit timestamp
in a lockless, safe and architecture-independent way. I have multiple
ideas for how to solve that:
- __ktime_get_real_seconds() is lockless, but can return
incorrect results on 32-bit architectures in the special case that
we are in the process of changing the time across the epoch, either
during the timer tick that overflows the seconds in 2038, or while
calling settimeofday.
- ktime_get_real_fast_ns() would work in this context, but does
require a call into the clocksource driver to return a high-resolution
timestamp. This may have undesired side-effects in the debugger,
since we want to limit the interactions with the rest of the kernel.
- Adding a ktime_get_real_fast_seconds() based on tk_fast_mono
plus tkr->base_real without the tk_clock_read() delta. Not sure about
the value of adding yet another interface here.
- Changing the existing ktime_get_real_seconds() to use
tk_fast_mono on 32-bit architectures rather than xtime_sec. I think
this could work, but am not entirely sure if this is an improvement.
I picked the first of those for simplicity here. It's technically
not correct but probably good enough as the time is only used for the
debugging output and the race will likely never be hit in practice.
Another downside is having to move the declaration into a public header
file.
Let me know if anyone has a different preference.
Cc: Andy Shevchenko <andriy.shevchenko(a)linux.intel.com>
Link: https://patchwork.kernel.org/patch/9775309/
Signed-off-by: Arnd Bergmann <arnd(a)arndb.de>
---
include/linux/timekeeping.h | 1 +
kernel/debug/kdb/kdb_main.c | 45 +++++---------------------------------
kernel/time/timekeeping_internal.h | 2 --
3 files changed, 6 insertions(+), 42 deletions(-)
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index eb98cbdbb323..9b59473556fe 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -41,6 +41,7 @@ struct timespec64 get_monotonic_coarse64(void);
extern void getrawmonotonic64(struct timespec64 *ts);
extern void ktime_get_ts64(struct timespec64 *ts);
extern time64_t ktime_get_seconds(void);
+extern time64_t __ktime_get_real_seconds(void);
extern time64_t ktime_get_real_seconds(void);
extern int __getnstimeofday64(struct timespec64 *tv);
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index c8146d53ca67..69e70f4021fe 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -2479,41 +2479,6 @@ static int kdb_kill(int argc, const char **argv)
return 0;
}
-struct kdb_tm {
- int tm_sec; /* seconds */
- int tm_min; /* minutes */
- int tm_hour; /* hours */
- int tm_mday; /* day of the month */
- int tm_mon; /* month */
- int tm_year; /* year */
-};
-
-static void kdb_gmtime(struct timespec *tv, struct kdb_tm *tm)
-{
- /* This will work from 1970-2099, 2100 is not a leap year */
- static int mon_day[] = { 31, 29, 31, 30, 31, 30, 31,
- 31, 30, 31, 30, 31 };
- memset(tm, 0, sizeof(*tm));
- tm->tm_sec = tv->tv_sec % (24 * 60 * 60);
- tm->tm_mday = tv->tv_sec / (24 * 60 * 60) +
- (2 * 365 + 1); /* shift base from 1970 to 1968 */
- tm->tm_min = tm->tm_sec / 60 % 60;
- tm->tm_hour = tm->tm_sec / 60 / 60;
- tm->tm_sec = tm->tm_sec % 60;
- tm->tm_year = 68 + 4*(tm->tm_mday / (4*365+1));
- tm->tm_mday %= (4*365+1);
- mon_day[1] = 29;
- while (tm->tm_mday >= mon_day[tm->tm_mon]) {
- tm->tm_mday -= mon_day[tm->tm_mon];
- if (++tm->tm_mon == 12) {
- tm->tm_mon = 0;
- ++tm->tm_year;
- mon_day[1] = 28;
- }
- }
- ++tm->tm_mday;
-}
-
/*
* Most of this code has been lifted from kernel/timer.c::sys_sysinfo().
* I cannot call that code directly from kdb, it has an unconditional
@@ -2539,8 +2504,8 @@ static void kdb_sysinfo(struct sysinfo *val)
*/
static int kdb_summary(int argc, const char **argv)
{
- struct timespec now;
- struct kdb_tm tm;
+ time64_t now;
+ struct tm tm;
struct sysinfo val;
if (argc)
@@ -2554,9 +2519,9 @@ static int kdb_summary(int argc, const char **argv)
kdb_printf("domainname %s\n", init_uts_ns.name.domainname);
kdb_printf("ccversion %s\n", __stringify(CCVERSION));
- now = __current_kernel_time();
- kdb_gmtime(&now, &tm);
- kdb_printf("date %04d-%02d-%02d %02d:%02d:%02d "
+ now = __ktime_get_real_seconds();
+ time64_to_tm(now, 0, &tm);
+ kdb_printf("date %04ld-%02d-%02d %02d:%02d:%02d "
"tz_minuteswest %d\n",
1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h
index 9a18f121f399..58e79485de1b 100644
--- a/kernel/time/timekeeping_internal.h
+++ b/kernel/time/timekeeping_internal.h
@@ -30,6 +30,4 @@ static inline u64 clocksource_delta(u64 now, u64 last, u64 mask)
}
#endif
-extern time64_t __ktime_get_real_seconds(void);
-
#endif /* _TIMEKEEPING_INTERNAL_H */
--
2.9.0
getnstimeofday() and timespec are deprecated since they can
overflow on 32-bit architectures. This simply changes to the
explicitly typed timespec64 version that doesn't have that
problem.
It would be nice to also convert to monotonic timestamps
and call ktime_get_ts64() rather than ktime_get_real_ts64(),
but that would be a user-visible change.
Signed-off-by: Arnd Bergmann <arnd(a)arndb.de>
---
drivers/s390/block/dasd.c | 10 +++++-----
drivers/s390/block/dasd_int.h | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 0f1ff0813493..f48b3d5082cf 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -758,7 +758,7 @@ static void dasd_profile_end_add_data(struct dasd_profile_info *data,
/* in case of an overflow, reset the whole profile */
if (data->dasd_io_reqs == UINT_MAX) {
memset(data, 0, sizeof(*data));
- getnstimeofday(&data->starttod);
+ ktime_get_real_ts64(&data->starttod);
}
data->dasd_io_reqs++;
data->dasd_io_sects += sectors;
@@ -893,7 +893,7 @@ void dasd_profile_reset(struct dasd_profile *profile)
return;
}
memset(data, 0, sizeof(*data));
- getnstimeofday(&data->starttod);
+ ktime_get_real_ts64(&data->starttod);
spin_unlock_bh(&profile->lock);
}
@@ -910,7 +910,7 @@ int dasd_profile_on(struct dasd_profile *profile)
kfree(data);
return 0;
}
- getnstimeofday(&data->starttod);
+ ktime_get_real_ts64(&data->starttod);
profile->data = data;
spin_unlock_bh(&profile->lock);
return 0;
@@ -994,8 +994,8 @@ static void dasd_stats_array(struct seq_file *m, unsigned int *array)
static void dasd_stats_seq_print(struct seq_file *m,
struct dasd_profile_info *data)
{
- seq_printf(m, "start_time %ld.%09ld\n",
- data->starttod.tv_sec, data->starttod.tv_nsec);
+ seq_printf(m, "start_time %lld.%09ld\n",
+ (s64)data->starttod.tv_sec, data->starttod.tv_nsec);
seq_printf(m, "total_requests %u\n", data->dasd_io_reqs);
seq_printf(m, "total_sectors %u\n", data->dasd_io_sects);
seq_printf(m, "total_pav %u\n", data->dasd_io_alias);
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index b095a23bcc0c..96709b1a7bf8 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -441,7 +441,7 @@ struct dasd_profile_info {
unsigned int dasd_io_nr_req[32]; /* hist. of # of requests in chanq */
/* new data */
- struct timespec starttod; /* time of start or last reset */
+ struct timespec64 starttod; /* time of start or last reset */
unsigned int dasd_io_alias; /* requests using an alias */
unsigned int dasd_io_tpm; /* requests using transport mode */
unsigned int dasd_read_reqs; /* total number of read requests */
--
2.9.0