linux/arch/arm64/lib
Xu Kuohai 6c9f86d363 arm64: insn: Add encoders for LDRSB/LDRSH/LDRSW
To support BPF sign-extend load instructions, add encoders for
LDRSB/LDRSH/LDRSW.

LDRSB/LDRSH/LDRSW (immediate) is encoded as follows:

     3     2 2   2   2                       1         0         0
     0     7 6   4   2                       0         5         0
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  | sz|1 1 1|0|0 1|opc|        imm12          |    Rn   |    Rt   |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

LDRSB/LDRSH/LDRSW (register) is encoded as follows:

     3     2 2   2   2 2         1     1 1   1         0         0
     0     7 6   4   2 1         6     3 2   0         5         0
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  | sz|1 1 1|0|0 0|opc|1|    Rm   | opt |S|1 0|    Rn   |    Rt   |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

where:

   - sz
     indicates whether 8-bit, 16-bit or 32-bit data is to be loaded

   - opc
     opc[1] (bit 23) is always 1 and opc[0] == 1 indicates regsize
     is 32-bit. Since BPF signed load instructions always exend the
     sign bit to bit 63 regardless of whether it loads an 8-bit,
     16-bit or 32-bit data. So only 64-bit register size is required.
     That is, it's sufficient to set field opc fixed to 0x2.

   - opt
     Indicates whether to sign extend the offset register Rm and the
     effective bits of Rm. We set opt to 0x7 (SXTX) since we'll use
     Rm as a sgined 64-bit value in BPF.

   - S
     Optional only when opt field is 0x3 (LSL)

In short, the above fields are encoded to the values listed below.

                   sz   opc  opt   S
LDRSB (immediate)  0x0  0x2  na    na
LDRSH (immediate)  0x1  0x2  na    na
LDRSW (immediate)  0x2  0x2  na    na
LDRSB (register)   0x0  0x2  0x7   0
LDRSH (register)   0x1  0x2  0x7   0
LDRSW (register)   0x2  0x2  0x7   0

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Florent Revest <revest@chromium.org>
Acked-by: Florent Revest <revest@chromium.org>
Link: https://lore.kernel.org/bpf/20230815154158.717901-2-xukuohai@huaweicloud.com
2023-08-18 15:45:34 +02:00
..
clear_page.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
clear_user.S arm64: extable: consolidate definitions 2021-10-21 10:45:22 +01:00
copy_from_user.S arm64: lib: __arch_copy_from_user(): fold fixups into body 2021-10-21 10:45:21 +01:00
copy_page.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
copy_template.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
copy_to_user.S arm64: lib: __arch_copy_to_user(): fold fixups into body 2021-10-21 10:45:21 +01:00
crc32.S arm64: lib: accelerate crc32_be 2022-01-31 11:21:43 +11:00
csum.c arm64: csum: Disable KASAN for do_csum() 2020-04-15 21:36:41 +01:00
delay.c arm64: Use WFxT for __delay() when possible 2022-04-20 13:24:44 +01:00
error-inject.c arm64: Add support for function error injection 2019-08-07 13:53:09 +01:00
insn.c arm64: insn: Add encoders for LDRSB/LDRSH/LDRSW 2023-08-18 15:45:34 +02:00
kasan_sw_tags.S arm64: Use BTI C directly and unconditionally 2021-12-14 18:12:58 +00:00
Makefile isystem: delete global -isystem compile option 2021-09-22 09:26:24 +09:00
memchr.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
memcmp.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
memcpy.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
memset.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
mte.S arm64/sysreg: Remove duplicate definitions from asm/sysreg.h 2022-12-01 17:31:12 +00:00
strchr.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
strcmp.S Merge branch 'for-next/strings' into for-next/core 2022-03-14 19:02:52 +00:00
strlen.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
strncmp.S Merge branch 'for-next/strings' into for-next/core 2022-03-14 19:02:52 +00:00
strnlen.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
strrchr.S arm64: clean up symbol aliasing 2022-02-22 16:21:34 +00:00
tishift.S arm64: lib: Use modern annotations for assembly functions 2020-01-08 12:23:02 +00:00
uaccess_flushcache.c arm: uaccess: Remove memcpy_page_flushcache() 2023-03-27 16:26:19 +01:00
xor-neon.c arm64: xor-neon: mark xor_arm64_neon_*() static 2023-05-25 17:44:01 +01:00