zfs/module/lua/setjmp
Alexander Lobakin b844489ec0 icp: properly fix all RETs in x86_64 Asm code
Commit 43569ee374 ("Fix objtool: missing int3 after ret warning")
addressed replacing all `ret`s in x86 asm code to a macro in the
Linux kernel in order to enable SLS. That was done by copying the
upstream macro definitions and fixed objtool complaints.
Since then, several more mitigations were introduced, including
Rethunk. It requires to have a jump to one of the thunks in order
to work, so the RET macro was changed again. And, as ZFS code
didn't use the mainline defition, but copied it, this is currently
missing.

Objtool reminds about it time to time (Clang 16, CONFIG_RETHUNK=y):

fs/zfs/lua/zlua.o: warning: objtool: setjmp+0x25: 'naked' return
 found in RETHUNK build
fs/zfs/lua/zlua.o: warning: objtool: longjmp+0x27: 'naked' return
 found in RETHUNK build

Do it the following way:
* if we're building under Linux, unconditionally include
  <linux/linkage.h> in the related files. It is available in x86
  sources since even pre-2.6 times, so doesn't need any conftests;
* then, if RET macro is available, it will be used directly, so that
  we will always have the version actual to the kernel we build;
* if there's no such macro, we define it as a simple `ret`, as it
  was on pre-SLS times.

This ensures we always have the up-to-date definition with no need
to update it manually, and at the same time is safe for the whole
variety of kernels ZFS module supports.
Then, there's a couple more "naked" rets left in the code, they're
just defined as:

	.byte 0xf3,0xc3

In fact, this is just:

	rep ret

`rep ret` instead of just `ret` seems to mitigate performance issues
on some old AMD processors and most likely makes no sense as of
today.
Anyways, address those rets, so that they will be protected with
Rethunk and SLS. Include <sys/asm_linkage.h> here which now always
has RET definition and replace those constructs with just RET.
This wipes the last couple of places with unpatched rets objtool's
been complaining about.

Reviewed-by: Attila Fülöp <attila@fueloep.org>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Closes #14035
2022-11-04 11:24:09 -07:00
..
setjmp.S Preliminary support for RV64G 2019-11-06 10:56:09 -08:00
setjmp_aarch64.S OpenZFS 7431 - ZFS Channel Programs 2018-02-08 15:28:18 -08:00
setjmp_arm.S Add longjmp support for Thumb-2 2020-04-29 17:30:13 -07:00
setjmp_i386.S Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
setjmp_mips.S OpenZFS 7431 - ZFS Channel Programs 2018-02-08 15:28:18 -08:00
setjmp_ppc.S Mark lua setjmp/longjmp for powerpc weak 2020-08-25 10:32:49 -07:00
setjmp_rv64g.S Preliminary support for RV64G 2019-11-06 10:56:09 -08:00
setjmp_s390x.S OpenZFS 7431 - ZFS Channel Programs 2018-02-08 15:28:18 -08:00
setjmp_sparc64.S OpenZFS 7431 - ZFS Channel Programs 2018-02-08 15:28:18 -08:00
setjmp_x86_64.S icp: properly fix all RETs in x86_64 Asm code 2022-11-04 11:24:09 -07:00