linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 4.14 13/45] selftests/x86: Add clock_gettime() tests to test_vdso
Date: Thu, 11 Oct 2018 17:39:40 +0200	[thread overview]
Message-ID: <20181011152509.415931947@linuxfoundation.org> (raw)
In-Reply-To: <20181011152508.885515042@linuxfoundation.org>

4.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Andy Lutomirski <luto@kernel.org>

commit 7c03e7035ac1cf2a6165754e4f3a49c2f1977838 upstream.

Now that the vDSO implementation of clock_gettime() is getting
reworked, add a selftest for it.  This tests that its output is
consistent with the syscall version.

This is marked for stable to serve as a test for commit

  715bd9d12f84 ("x86/vdso: Fix asm constraints on vDSO syscall fallbacks")

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/082399674de2619b2befd8c0dde49b260605b126.1538422295.git.luto@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 tools/testing/selftests/x86/test_vdso.c |   99 ++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)

--- a/tools/testing/selftests/x86/test_vdso.c
+++ b/tools/testing/selftests/x86/test_vdso.c
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <sched.h>
 #include <stdbool.h>
+#include <limits.h>
 
 #ifndef SYS_getcpu
 # ifdef __x86_64__
@@ -31,6 +32,10 @@
 
 int nerrs = 0;
 
+typedef int (*vgettime_t)(clockid_t, struct timespec *);
+
+vgettime_t vdso_clock_gettime;
+
 typedef long (*getcpu_t)(unsigned *, unsigned *, void *);
 
 getcpu_t vgetcpu;
@@ -95,6 +100,10 @@ static void fill_function_pointers()
 		printf("Warning: failed to find getcpu in vDSO\n");
 
 	vgetcpu = (getcpu_t) vsyscall_getcpu();
+
+	vdso_clock_gettime = (vgettime_t)dlsym(vdso, "__vdso_clock_gettime");
+	if (!vdso_clock_gettime)
+		printf("Warning: failed to find clock_gettime in vDSO\n");
 }
 
 static long sys_getcpu(unsigned * cpu, unsigned * node,
@@ -103,6 +112,11 @@ static long sys_getcpu(unsigned * cpu, u
 	return syscall(__NR_getcpu, cpu, node, cache);
 }
 
+static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)
+{
+	return syscall(__NR_clock_gettime, id, ts);
+}
+
 static void test_getcpu(void)
 {
 	printf("[RUN]\tTesting getcpu...\n");
@@ -155,10 +169,95 @@ static void test_getcpu(void)
 	}
 }
 
+static bool ts_leq(const struct timespec *a, const struct timespec *b)
+{
+	if (a->tv_sec != b->tv_sec)
+		return a->tv_sec < b->tv_sec;
+	else
+		return a->tv_nsec <= b->tv_nsec;
+}
+
+static char const * const clocknames[] = {
+	[0] = "CLOCK_REALTIME",
+	[1] = "CLOCK_MONOTONIC",
+	[2] = "CLOCK_PROCESS_CPUTIME_ID",
+	[3] = "CLOCK_THREAD_CPUTIME_ID",
+	[4] = "CLOCK_MONOTONIC_RAW",
+	[5] = "CLOCK_REALTIME_COARSE",
+	[6] = "CLOCK_MONOTONIC_COARSE",
+	[7] = "CLOCK_BOOTTIME",
+	[8] = "CLOCK_REALTIME_ALARM",
+	[9] = "CLOCK_BOOTTIME_ALARM",
+	[10] = "CLOCK_SGI_CYCLE",
+	[11] = "CLOCK_TAI",
+};
+
+static void test_one_clock_gettime(int clock, const char *name)
+{
+	struct timespec start, vdso, end;
+	int vdso_ret, end_ret;
+
+	printf("[RUN]\tTesting clock_gettime for clock %s (%d)...\n", name, clock);
+
+	if (sys_clock_gettime(clock, &start) < 0) {
+		if (errno == EINVAL) {
+			vdso_ret = vdso_clock_gettime(clock, &vdso);
+			if (vdso_ret == -EINVAL) {
+				printf("[OK]\tNo such clock.\n");
+			} else {
+				printf("[FAIL]\tNo such clock, but __vdso_clock_gettime returned %d\n", vdso_ret);
+				nerrs++;
+			}
+		} else {
+			printf("[WARN]\t clock_gettime(%d) syscall returned error %d\n", clock, errno);
+		}
+		return;
+	}
+
+	vdso_ret = vdso_clock_gettime(clock, &vdso);
+	end_ret = sys_clock_gettime(clock, &end);
+
+	if (vdso_ret != 0 || end_ret != 0) {
+		printf("[FAIL]\tvDSO returned %d, syscall errno=%d\n",
+		       vdso_ret, errno);
+		nerrs++;
+		return;
+	}
+
+	printf("\t%llu.%09ld %llu.%09ld %llu.%09ld\n",
+	       (unsigned long long)start.tv_sec, start.tv_nsec,
+	       (unsigned long long)vdso.tv_sec, vdso.tv_nsec,
+	       (unsigned long long)end.tv_sec, end.tv_nsec);
+
+	if (!ts_leq(&start, &vdso) || !ts_leq(&vdso, &end)) {
+		printf("[FAIL]\tTimes are out of sequence\n");
+		nerrs++;
+	}
+}
+
+static void test_clock_gettime(void)
+{
+	for (int clock = 0; clock < sizeof(clocknames) / sizeof(clocknames[0]);
+	     clock++) {
+		test_one_clock_gettime(clock, clocknames[clock]);
+	}
+
+	/* Also test some invalid clock ids */
+	test_one_clock_gettime(-1, "invalid");
+	test_one_clock_gettime(INT_MIN, "invalid");
+	test_one_clock_gettime(INT_MAX, "invalid");
+}
+
 int main(int argc, char **argv)
 {
 	fill_function_pointers();
 
+	test_clock_gettime();
+
+	/*
+	 * Test getcpu() last so that, if something goes wrong setting affinity,
+	 * we still run the other tests.
+	 */
 	test_getcpu();
 
 	return nerrs ? 1 : 0;



  parent reply	other threads:[~2018-10-11 15:45 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-11 15:39 [PATCH 4.14 00/45] 4.14.76-stable review Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 01/45] perf/core: Add sanity check to deal with pinned event failure Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 02/45] mm: migration: fix migration of huge PMD shared pages Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 03/45] mm, thp: fix mlocking THP page with migration enabled Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 04/45] mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 05/45] KVM: x86: fix L1TFs MMIO GFN calculation Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 06/45] blk-mq: I/O and timer unplugs are inverted in blktrace Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 07/45] clocksource/drivers/timer-atmel-pit: Properly handle error cases Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 08/45] fbdev/omapfb: fix omapfb_memory_read infoleak Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 09/45] xen-netback: fix input validation in xenvif_set_hash_mapping() Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 10/45] drm/amdgpu: Fix vce work queue was not cancelled when suspend Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 11/45] drm/syncobj: Dont leak fences when WAIT_FOR_SUBMIT is set Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 12/45] x86/vdso: Fix asm constraints on vDSO syscall fallbacks Greg Kroah-Hartman
2018-10-11 15:39 ` Greg Kroah-Hartman [this message]
2018-10-11 15:39 ` [PATCH 4.14 14/45] x86/vdso: Only enable vDSO retpolines when enabled and supported Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 15/45] x86/vdso: Fix vDSO syscall fallback asm constraint regression Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 16/45] PCI: Reprogram bridge prefetch registers on resume Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 17/45] mac80211: fix setting IEEE80211_KEY_FLAG_RX_MGMT for AP mode keys Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 18/45] PM / core: Clear the direct_complete flag on errors Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 19/45] dm cache metadata: ignore hints array being too small during resize Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 20/45] dm cache: fix resize crash if user doesnt reload cache table Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 21/45] xhci: Add missing CAS workaround for Intel Sunrise Point xHCI Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 22/45] usb: xhci-mtk: resume USB3 roothub first Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 23/45] USB: serial: simple: add Motorola Tetra MTP6550 id Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 24/45] usb: cdc_acm: Do not leak URB buffers Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 25/45] tty: Drop tty->count on tty_reopen() failure Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 26/45] of: unittest: Disable interrupt node tests for old world MAC systems Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 27/45] perf annotate: Use asprintf when formatting objdump command line Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 28/45] perf tools: Fix python extension build for gcc 8 Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 29/45] cgroup/cpuset: remove circular dependency deadlock Greg Kroah-Hartman
2018-10-11 19:33   ` Sudip Mukherjee
2018-10-12 11:05     ` Greg Kroah-Hartman
2018-10-16 18:46       ` Amit Pundir
2018-10-11 15:39 ` [PATCH 4.14 30/45] ath10k: fix use-after-free in ath10k_wmi_cmd_send_nowait Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 31/45] ath10k: fix kernel panic issue during pci probe Greg Kroah-Hartman
2018-10-11 15:39 ` [PATCH 4.14 32/45] nvme_fc: fix ctrl create failures racing with workq items Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 33/45] powerpc/lib/code-patching: refactor patch_instruction() Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 34/45] powerpc: Avoid code patching freed init sections Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 35/45] powerpc/lib: fix book3s/32 boot failure due to code patching Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 36/45] ARC: clone syscall to setp r25 as thread pointer Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 37/45] crypto: chelsio - Fix memory corruption in DMA Mapped buffers Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 38/45] perf utils: Move is_directory() to path.h Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 39/45] f2fs: fix invalid memory access Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 40/45] ucma: fix a use-after-free in ucma_resolve_ip() Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 41/45] ubifs: Check for name being NULL while mounting Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 42/45] rds: rds_ib_recv_alloc_cache() should call alloc_percpu_gfp() instead Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 43/45] virtio_balloon: fix deadlock on OOM Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 44/45] virtio_balloon: fix increment of vb->num_pfns in fill_balloon() Greg Kroah-Hartman
2018-10-11 15:40 ` [PATCH 4.14 45/45] ath10k: fix scan crash due to incorrect length calculation Greg Kroah-Hartman
2018-10-11 22:37 ` [PATCH 4.14 00/45] 4.14.76-stable review Shuah Khan
2018-10-12  4:27 ` Naresh Kamboju
2018-10-12  7:50 ` Jon Hunter
2018-10-12 10:24   ` Greg Kroah-Hartman
2018-10-12 15:43 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181011152509.415931947@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).