From a4115cfea9b70bcba9a339cd5911f309510b649c Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 2 May 2021 11:53:34 +0200 Subject: [PATCH] base-linux: discharge timestamp on AARCH64 The kernel-agnostic 'Trace::timestamp' function for arm_64 executes the 'mrs %0, pmccntr_el0' instruction, which is not permitted for user-level programs on Linux. This patch shadows the generic timestamp.h header with dummy that returns zero. This return value prompts the timeout framework to disable the interpolation of time based on timestamps. This avoid the illegal-instruction abort but comes with two llimitations: First, time measurements are effectlively limited to a granulariry of 1 millisecond (deliberately constrained by the timer driver). The quirk is applied when using the base-linux API. Should a generic application (that uses the base API only) call 'Trace::timestamp' directly, the illegal instruction is executed. Issue #4136 --- .../include/spec/arm_64/trace/timestamp.h | 34 +++++++++++++++++++ .../recipes/api/base-linux/content.mk | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 repos/base-linux/include/spec/arm_64/trace/timestamp.h diff --git a/repos/base-linux/include/spec/arm_64/trace/timestamp.h b/repos/base-linux/include/spec/arm_64/trace/timestamp.h new file mode 100644 index 0000000000..741528fb52 --- /dev/null +++ b/repos/base-linux/include/spec/arm_64/trace/timestamp.h @@ -0,0 +1,34 @@ +/* + * \brief Trace timestamp + * \author Norman Feske + * \date 2021-05-01 + */ + +/* + * Copyright (C) 2021 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _INCLUDE__SPEC__ARM_64__TRACE__TIMESTAMP_H_ +#define _INCLUDE__SPEC__ARM_64__TRACE__TIMESTAMP_H_ + +#include + +namespace Genode { namespace Trace { + + typedef uint64_t Timestamp; + + /* + * In Linux/AARCH64, the 'mrs' instruction cannot be executed in user land. + * It triggers the abort of the program with an illegal-instruction + * exception. + * + * By returning 0, we discharge the timestamp-based interpolation of + * 'Timer::Connection::curr_time', falling back to a precision of 1 ms. + */ + inline Timestamp timestamp() { return 0; } +} } + +#endif /* _INCLUDE__SPEC__ARM_64__TRACE__TIMESTAMP_H_ */ diff --git a/repos/base-linux/recipes/api/base-linux/content.mk b/repos/base-linux/recipes/api/base-linux/content.mk index 5c173fbb00..c77cf9d735 100644 --- a/repos/base-linux/recipes/api/base-linux/content.mk +++ b/repos/base-linux/recipes/api/base-linux/content.mk @@ -1,4 +1,4 @@ -FROM_BASE_LINUX := etc src/lib/syscall src/lib/lx_hybrid lib/import +FROM_BASE_LINUX := etc src/lib/syscall src/lib/lx_hybrid lib/import include FROM_BASE_LINUX_AND_BASE := lib/mk src/lib/base src/include FROM_BASE := src/lib/timeout