2017-11-20 19:00:20

by Palmer Dabbelt

[permalink] [raw]
Subject: RISC-V: User-Visible ABI Cleanup

This patch set contains all the user-visible ABI changes that we currently know
about. There might be a few more as we get through the glibc upstreaming
process, though. Most of the changes are pretty minor:

* Some VDSO symbols that weren't defined were versioned, which doesn't make any
sense.
* We were missing some common VDSO entries.
* The instruction cache is flushed when making a dirty page executable.
* A system call (and VDSO entry) has been added to flush the instruction cache.

There's one big, implicit ABI change here: 'fence.i' is no longer meaningful to
execute from Linux userspace, instead users are expected to call the new VDSO
entry. There's a lot more info in the commit, but the short version is:

* 'fence.i' performs an instruction cache flush on the local hart.
* There's no way for userspace to map threads to harts, so there's no way to
perform global instrucion cache flushes.
* The supervisor can't trap 'fence.i', so the only other way to maintain
correct behavior would be to flush the instruction cache before returning to
userspace.

We don't want to take the performance hit of flushing the instruction cache
every time we return to userspace, so we're breaking the ABI to mandate that
users call the VDSO entry instead of using 'fence.i'. Since we haven't had a
tarball release of Linux yet, I think this ABI break is still kosher. Of
course, we won't do this once there's been a release :).

Sorry this was a bit late, but I'm really hoping to get this into 4.15 so we
don't end up with a broken ABI in our first kernel release.

[PATCH 1/4] RISC-V: Remove __vdso_cmpxchg{32,64} symbol versions
[PATCH 2/4] RISC-V: Add VDSO entries for
[PATCH 3/4] RISC-V: Flush I$ when making a dirty page executable
[PATCH 4/4] RISC-V: Allow userspace to flush the instruction cache

From 1584466812562577885@xxx Sun Nov 19 04:21:44 +0000 2017
X-GM-THRID: 1582451757077353071
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread


2017-11-20 19:00:08

by Palmer Dabbelt

[permalink] [raw]
Subject: [PATCH 2/4] RISC-V: Add VDSO entries for clock_get/gettimeofday/getcpu

From: Andrew Waterman <[email protected]>

For now these are just placeholders that execute the syscall. We will
later optimize them to avoid kernel crossings, but we'd like to have the
VDSO entries from the first released kernel version to make the ABI
simpler.

Signed-off-by: Andrew Waterman <[email protected]>
Signed-off-by: Palmer Dabbelt <[email protected]>
---
arch/riscv/kernel/vdso/Makefile | 6 +++++-
arch/riscv/kernel/vdso/clock_getres.S | 26 ++++++++++++++++++++++++++
arch/riscv/kernel/vdso/clock_gettime.S | 26 ++++++++++++++++++++++++++
arch/riscv/kernel/vdso/getcpu.S | 26 ++++++++++++++++++++++++++
arch/riscv/kernel/vdso/gettimeofday.S | 26 ++++++++++++++++++++++++++
arch/riscv/kernel/vdso/vdso.lds.S | 4 ++++
6 files changed, 113 insertions(+), 1 deletion(-)
create mode 100644 arch/riscv/kernel/vdso/clock_getres.S
create mode 100644 arch/riscv/kernel/vdso/clock_gettime.S
create mode 100644 arch/riscv/kernel/vdso/getcpu.S
create mode 100644 arch/riscv/kernel/vdso/gettimeofday.S

diff --git a/arch/riscv/kernel/vdso/Makefile b/arch/riscv/kernel/vdso/Makefile
index 523d0a8ac8db..2dcc4f3070bc 100644
--- a/arch/riscv/kernel/vdso/Makefile
+++ b/arch/riscv/kernel/vdso/Makefile
@@ -1,7 +1,11 @@
# Copied from arch/tile/kernel/vdso/Makefile

# Symbols present in the vdso
-vdso-syms = rt_sigreturn
+vdso-syms = rt_sigreturn
+vdso-syms += gettimeofday
+vdso-syms += clock_gettime
+vdso-syms += clock_getres
+vdso-syms += getcpu

# Files to link into the vdso
obj-vdso = $(patsubst %, %.o, $(vdso-syms))
diff --git a/arch/riscv/kernel/vdso/clock_getres.S b/arch/riscv/kernel/vdso/clock_getres.S
new file mode 100644
index 000000000000..edf7e2339648
--- /dev/null
+++ b/arch/riscv/kernel/vdso/clock_getres.S
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ * 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, version 2.
+ *
+ * This program is distributed in the hope that it will 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.
+ */
+
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+ .text
+/* int __vdso_clock_getres(clockid_t clock_id, struct timespec *res); */
+ENTRY(__vdso_clock_getres)
+ .cfi_startproc
+ /* For now, just do the syscall. */
+ li a7, __NR_clock_getres
+ ecall
+ ret
+ .cfi_endproc
+ENDPROC(__vdso_clock_getres)
diff --git a/arch/riscv/kernel/vdso/clock_gettime.S b/arch/riscv/kernel/vdso/clock_gettime.S
new file mode 100644
index 000000000000..aac65676c6d5
--- /dev/null
+++ b/arch/riscv/kernel/vdso/clock_gettime.S
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ * 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, version 2.
+ *
+ * This program is distributed in the hope that it will 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.
+ */
+
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+ .text
+/* int __vdso_clock_gettime(clockid_t clock_id, struct timespec *tp); */
+ENTRY(__vdso_clock_gettime)
+ .cfi_startproc
+ /* For now, just do the syscall. */
+ li a7, __NR_clock_gettime
+ ecall
+ ret
+ .cfi_endproc
+ENDPROC(__vdso_clock_gettime)
diff --git a/arch/riscv/kernel/vdso/getcpu.S b/arch/riscv/kernel/vdso/getcpu.S
new file mode 100644
index 000000000000..cc7e98924484
--- /dev/null
+++ b/arch/riscv/kernel/vdso/getcpu.S
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ * 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, version 2.
+ *
+ * This program is distributed in the hope that it will 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.
+ */
+
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+ .text
+/* int __vdso_getcpu(unsigned *cpu, unsigned *node, void *unused); */
+ENTRY(__vdso_getcpu)
+ .cfi_startproc
+ /* For now, just do the syscall. */
+ li a7, __NR_getcpu
+ ecall
+ ret
+ .cfi_endproc
+ENDPROC(__vdso_getcpu)
diff --git a/arch/riscv/kernel/vdso/gettimeofday.S b/arch/riscv/kernel/vdso/gettimeofday.S
new file mode 100644
index 000000000000..da85d33e8990
--- /dev/null
+++ b/arch/riscv/kernel/vdso/gettimeofday.S
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017 SiFive
+ *
+ * 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, version 2.
+ *
+ * This program is distributed in the hope that it will 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.
+ */
+
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+ .text
+/* int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); */
+ENTRY(__vdso_gettimeofday)
+ .cfi_startproc
+ /* For now, just do the syscall. */
+ li a7, __NR_gettimeofday
+ ecall
+ ret
+ .cfi_endproc
+ENDPROC(__vdso_gettimeofday)
diff --git a/arch/riscv/kernel/vdso/vdso.lds.S b/arch/riscv/kernel/vdso/vdso.lds.S
index 3ac08eebd11d..c7543c6a00f9 100644
--- a/arch/riscv/kernel/vdso/vdso.lds.S
+++ b/arch/riscv/kernel/vdso/vdso.lds.S
@@ -70,6 +70,10 @@ VERSION
LINUX_4.15 {
global:
__vdso_rt_sigreturn;
+ __vdso_gettimeofday;
+ __vdso_clock_gettime;
+ __vdso_clock_getres;
+ __vdso_getcpu;
local: *;
};
}
--
2.13.6


From 1584340977328906809@xxx Fri Nov 17 19:01:38 +0000 2017
X-GM-THRID: 1584340977328906809
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread