!112 [sync] PR-104: riscv64: 修复rdcycle汇编指令导致的崩溃问题
From: @openeuler-sync-bot Reviewed-by: @dillon_chen Signed-off-by: @dillon_chen
This commit is contained in:
commit
0b2098bd46
100
mariadb-RISC-V-use-RDTIME-for-cycle-timer.patch
Normal file
100
mariadb-RISC-V-use-RDTIME-for-cycle-timer.patch
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
From 841bfb4641f4cbad16a3aeb07fa462dcd4449cac Mon Sep 17 00:00:00 2001
|
||||||
|
From: IZUMI-Zu <binshuo.oerv@isrc.iscas.ac.cn>
|
||||||
|
Date: Fri, 23 Aug 2024 00:00:12 +0800
|
||||||
|
Subject: [PATCH] RISC-V: use RDTIME for cycle timer and disable __builtin_readcyclecounter
|
||||||
|
|
||||||
|
This commit backports and extends the fixes from MariaDB/server PRs #1981
|
||||||
|
and #2980 to address the RISC-V RDCYCLE privileged instruction issue.
|
||||||
|
|
||||||
|
Key changes:
|
||||||
|
1. Use RDTIME instead of RDCYCLE for cycle timer on RISC-V
|
||||||
|
2. Disable __builtin_readcyclecounter() for RISC-V as LLVM generates RDCYCLE
|
||||||
|
|
||||||
|
Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on RISC-V and can't be used directly from userland.
|
||||||
|
There is a sysctl option to change that as a transition period, but it will eventually disappear.
|
||||||
|
|
||||||
|
Use RDTIME instead, which while less accurate has the advantage of being synchronized between CPU (and thus monotonic)
|
||||||
|
and of constant frequency.
|
||||||
|
|
||||||
|
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3
|
||||||
|
|
||||||
|
Backported-from: https://github.com/MariaDB/server/pull/1981
|
||||||
|
https://github.com/MariaDB/server/pull/2980
|
||||||
|
---
|
||||||
|
include/my_rdtsc.h | 26 +++++++++++++++++++++++++-
|
||||||
|
mysys/my_rdtsc.c | 2 ++
|
||||||
|
2 files changed, 27 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/include/my_rdtsc.h b/include/my_rdtsc.h
|
||||||
|
index e8101516..880625fa 100644
|
||||||
|
--- a/include/my_rdtsc.h
|
||||||
|
+++ b/include/my_rdtsc.h
|
||||||
|
@@ -91,6 +91,7 @@ C_MODE_START
|
||||||
|
On AARCH64, we use the generic timer base register. We override clang
|
||||||
|
implementation for aarch64 as it access a PMU register which is not
|
||||||
|
guaranteed to be active.
|
||||||
|
+ On RISC-V, we use the rdtime instruction to read from mtime register.
|
||||||
|
|
||||||
|
Sadly, we have nothing for the Digital Alpha, MIPS, Motorola m68k,
|
||||||
|
HP PA-RISC or other non-mainstream (or obsolete) processors.
|
||||||
|
@@ -128,7 +129,7 @@ C_MODE_START
|
||||||
|
*/
|
||||||
|
static inline ulonglong my_timer_cycles(void)
|
||||||
|
{
|
||||||
|
-# if __has_builtin(__builtin_readcyclecounter) && !defined (__aarch64__)
|
||||||
|
+# if __has_builtin(__builtin_readcyclecounter) && !defined(__aarch64__) && !defined(__riscv)
|
||||||
|
return __builtin_readcyclecounter();
|
||||||
|
# elif defined _WIN32 || defined __i386__ || defined __x86_64__
|
||||||
|
return __rdtsc();
|
||||||
|
@@ -173,6 +174,28 @@ static inline ulonglong my_timer_cycles(void)
|
||||||
|
__asm __volatile("mrs %0, CNTVCT_EL0" : "=&r" (result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
+#elif defined(__riscv)
|
||||||
|
+ /* Use RDTIME (and RDTIMEH on riscv32) */
|
||||||
|
+ {
|
||||||
|
+# if __riscv_xlen == 32
|
||||||
|
+ ulong result_lo, result_hi0, result_hi1;
|
||||||
|
+ /* Implemented in assembly because Clang insisted on branching. */
|
||||||
|
+ __asm __volatile__(
|
||||||
|
+ "rdtimeh %0\n"
|
||||||
|
+ "rdtime %1\n"
|
||||||
|
+ "rdtimeh %2\n"
|
||||||
|
+ "sub %0, %0, %2\n"
|
||||||
|
+ "seqz %0, %0\n"
|
||||||
|
+ "sub %0, zero, %0\n"
|
||||||
|
+ "and %1, %1, %0\n"
|
||||||
|
+ : "=r"(result_hi0), "=r"(result_lo), "=r"(result_hi1));
|
||||||
|
+ return (static_cast<ulonglong>(result_hi1) << 32) | result_lo;
|
||||||
|
+# else
|
||||||
|
+ ulonglong result;
|
||||||
|
+ __asm __volatile__("rdtime %0" : "=r"(result));
|
||||||
|
+ return result;
|
||||||
|
+ }
|
||||||
|
+# endif
|
||||||
|
#elif defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME)
|
||||||
|
/* gethrtime may appear as either cycle or nanosecond counter */
|
||||||
|
return (ulonglong) gethrtime();
|
||||||
|
@@ -231,6 +254,7 @@ C_MODE_END
|
||||||
|
#define MY_TIMER_ROUTINE_GETSYSTEMTIMEASFILETIME 26
|
||||||
|
#define MY_TIMER_ROUTINE_ASM_S390 28
|
||||||
|
#define MY_TIMER_ROUTINE_AARCH64 29
|
||||||
|
+#define MY_TIMER_ROUTINE_RISCV 30
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
diff --git a/mysys/my_rdtsc.c b/mysys/my_rdtsc.c
|
||||||
|
index 1503a5db..ffd81602 100644
|
||||||
|
--- a/mysys/my_rdtsc.c
|
||||||
|
+++ b/mysys/my_rdtsc.c
|
||||||
|
@@ -384,6 +384,8 @@ void my_timer_init(MY_TIMER_INFO *mti)
|
||||||
|
mti->cycles.routine= MY_TIMER_ROUTINE_ASM_S390;
|
||||||
|
#elif defined(__GNUC__) && defined (__aarch64__)
|
||||||
|
mti->cycles.routine= MY_TIMER_ROUTINE_AARCH64;
|
||||||
|
+#elif defined(__GNUC__) && defined (__riscv)
|
||||||
|
+ mti->cycles.routine= MY_TIMER_ROUTINE_RISCV;
|
||||||
|
#elif defined(HAVE_SYS_TIMES_H) && defined(HAVE_GETHRTIME)
|
||||||
|
mti->cycles.routine= MY_TIMER_ROUTINE_GETHRTIME;
|
||||||
|
#else
|
||||||
|
--
|
||||||
|
2.46.0
|
||||||
@ -1,30 +0,0 @@
|
|||||||
# Fixing conflict with groonga package
|
|
||||||
# https://bugzilla.redhat.com/show_bug.cgi?id=1763287
|
|
||||||
|
|
||||||
--- mariadb-10.3.18/storage/mroonga/vendor/groonga/CMakeLists.txt.withoutoption 2019-11-11 14:01:07.762595716 +0100
|
|
||||||
+++ mariadb-10.3.18/storage/mroonga/vendor/groonga/CMakeLists.txt 2019-11-11 14:33:05.224012458 +0100
|
|
||||||
@@ -86,7 +86,9 @@
|
|
||||||
set(INCLUDE_DIR "include")
|
|
||||||
set(GRN_INCLUDE_DIR "include/groonga")
|
|
||||||
set(DATA_DIR "share")
|
|
||||||
-set(GRN_DATA_DIR "${DATA_DIR}/${GRN_PROJECT_NAME}")
|
|
||||||
+if(NOT DEFINED GRN_DATA_DIR)
|
|
||||||
+ set(GRN_DATA_DIR "${DATA_DIR}/${GRN_PROJECT_NAME}")
|
|
||||||
+endif()
|
|
||||||
set(CONFIG_DIR "etc")
|
|
||||||
set(GRN_CONFIG_DIR "${CONFIG_DIR}/${GRN_PROJECT_NAME}")
|
|
||||||
set(GRN_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${GRN_CONFIG_DIR}/groonga.conf")
|
|
||||||
|
|
||||||
--- mariadb-10.3.18/storage/mroonga/vendor/groonga/vendor/plugins/groonga-normalizer-mysql/CMakeLists.txt.withoutoption 2019-11-11 14:34:22.661005715 +0100
|
|
||||||
+++ mariadb-10.3.18/storage/mroonga/vendor/groonga/vendor/plugins/groonga-normalizer-mysql/CMakeLists.txt 2019-11-11 14:35:59.962244120 +0100
|
|
||||||
@@ -16,7 +16,9 @@
|
|
||||||
# MA 02110-1335 USA
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.6)
|
|
||||||
-set(GROONGA_NORMALIZER_MYSQL_PROJECT_NAME "groonga-normalizer-mysql")
|
|
||||||
+if (NOT DEFINED GROONGA_NORMALIZER_MYSQL_PROJECT_NAME)
|
|
||||||
+ set(GROONGA_NORMALIZER_MYSQL_PROJECT_NAME "groonga-normalizer-mysql")
|
|
||||||
+endif()
|
|
||||||
project("${GROONGA_NORMALIZER_MYSQL_PROJECT_NAME}")
|
|
||||||
|
|
||||||
if(DEFINED GROONGA_NORMALIZER_MYSQL_EMBED)
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
diff -up mariadb-10.1.19/mysql-test/r/ssl_8k_key.result.sslbak mariadb-10.1.19/mysql-test/r/ssl_8k_key.result
|
|
||||||
--- mariadb-10.1.19/mysql-test/r/ssl_8k_key.result.sslbak 2016-11-24 08:55:21.637000000 -0500
|
|
||||||
+++ mariadb-10.1.19/mysql-test/r/ssl_8k_key.result 2016-11-24 08:55:55.853000000 -0500
|
|
||||||
@@ -1,2 +1,2 @@
|
|
||||||
-Variable_name Value
|
|
||||||
-Ssl_cipher DHE-RSA-AES256-SHA
|
|
||||||
+have_ssl
|
|
||||||
+1
|
|
||||||
diff -up mariadb-10.1.19/mysql-test/t/ssl_8k_key.test.sslbak mariadb-10.1.19/mysql-test/t/ssl_8k_key.test
|
|
||||||
--- mariadb-10.1.19/mysql-test/t/ssl_8k_key.test.sslbak 2016-11-24 08:54:10.485000000 -0500
|
|
||||||
+++ mariadb-10.1.19/mysql-test/t/ssl_8k_key.test 2016-11-24 08:54:35.724000000 -0500
|
|
||||||
@@ -5,7 +5,7 @@
|
|
||||||
#
|
|
||||||
# Bug#29784 YaSSL assertion failure when reading 8k key.
|
|
||||||
#
|
|
||||||
---exec $MYSQL --ssl --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem -e "SHOW STATUS LIKE 'ssl_Cipher'" 2>&1
|
|
||||||
+--exec $MYSQL --ssl --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'" 2>&1
|
|
||||||
|
|
||||||
## This test file is for testing encrypted communication only, not other
|
|
||||||
## encryption routines that the SSL library happens to provide!
|
|
||||||
|
|
||||||
@ -74,7 +74,7 @@
|
|||||||
|
|
||||||
Name: mariadb
|
Name: mariadb
|
||||||
Version: 10.5.25
|
Version: 10.5.25
|
||||||
Release: 1
|
Release: 2
|
||||||
Epoch: 4
|
Epoch: 4
|
||||||
|
|
||||||
Summary: A very fast and robust SQL database server
|
Summary: A very fast and robust SQL database server
|
||||||
@ -112,6 +112,8 @@ Patch9: %{pkgnamepatch}-ownsetup.patch
|
|||||||
Patch10: %{pkgnamepatch}-ssl-cipher-tests.patch
|
Patch10: %{pkgnamepatch}-ssl-cipher-tests.patch
|
||||||
# Patch11: Use PCDIR CMake option, if configured
|
# Patch11: Use PCDIR CMake option, if configured
|
||||||
Patch11: %{pkgnamepatch}-pcdir.patch
|
Patch11: %{pkgnamepatch}-pcdir.patch
|
||||||
|
# Patch12: RISC-V: use RDTIME for cycle timer
|
||||||
|
Patch12: %{pkgnamepatch}-RISC-V-use-RDTIME-for-cycle-timer.patch
|
||||||
|
|
||||||
BuildRequires: make
|
BuildRequires: make
|
||||||
BuildRequires: cmake gcc-c++
|
BuildRequires: cmake gcc-c++
|
||||||
@ -623,6 +625,7 @@ sources.
|
|||||||
%patch -P9 -p1
|
%patch -P9 -p1
|
||||||
%patch -P10 -p1
|
%patch -P10 -p1
|
||||||
%patch -P11 -p1
|
%patch -P11 -p1
|
||||||
|
%patch -P12 -p1
|
||||||
|
|
||||||
# Remove JAR files that upstream puts into tarball
|
# Remove JAR files that upstream puts into tarball
|
||||||
find . -name "*.jar" -type f -exec rm --verbose -f {} \;
|
find . -name "*.jar" -type f -exec rm --verbose -f {} \;
|
||||||
@ -1474,6 +1477,9 @@ fi
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sun Aug 18 2024 binshuo <binshuo.oerv@isrc.iscas.ac.cn> - 4:10.5.25-2
|
||||||
|
- RISC-V: fix 'rdcycle' SIGILL
|
||||||
|
|
||||||
* Tue May 28 2024 xiejing <xiejing@kylinos.cn> - 4:10.5.25-1
|
* Tue May 28 2024 xiejing <xiejing@kylinos.cn> - 4:10.5.25-1
|
||||||
- Bump to 10.5.25 for resolving CVE-2024-21096
|
- Bump to 10.5.25 for resolving CVE-2024-21096
|
||||||
- Fix version description in systemd service file
|
- Fix version description in systemd service file
|
||||||
@ -1569,4 +1575,3 @@ fi
|
|||||||
|
|
||||||
* Wed Sep 11 2019 openEuler Buildteam <buildteam@openeuler.org> - 3:10.3.9-3
|
* Wed Sep 11 2019 openEuler Buildteam <buildteam@openeuler.org> - 3:10.3.9-3
|
||||||
- Package init
|
- Package init
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user