linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] arm64: insn: Generate 64 bit mask immediates correctly
@ 2022-01-27 16:21 James Morse
  2022-01-27 16:21 ` [PATCH 1/3] arm64: selftests: Generate all the possible logical immediates as a header James Morse
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: James Morse @ 2022-01-27 16:21 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kselftest
  Cc: Catalin Marinas, Will Deacon, Marc Zyngier, Shuah Khan,
	Mark Brown, james.morse

Hello,

aarch64_insn_gen_logical_immediate() is generating the wrong code if
it is handed a 64bit immediate which has a single span of 1s (i.e. a
mask), with bit 63 set, and 0s in the remaining upper 32 bits.
Clear as mud. An example always helps: 0x800000003fffffff would be wrongly
encoded, but 0x000000003fffffff is unaffected.

It would appear eBPF is unable to hit these cases, as build_insn()'s
imm value is a s32, so when used with BPF_ALU64, the sign-extended
u64 immediate would always have all-1s or all-0s in the upper 32 bits.

KVM does not generate a va_mask with any of the top bits set as these
VA wouldn't be usable with TTBR0_EL2.

Patch 3 fixes it, and doesn't depend on the rest of the series.

As the instruction encoder is a source of headaches, the first two patches
add tests to help illustrate there is a problem, and that patch 3 fixes it.

The tests generate a header file of the expected values so it can be compared
against other sources of the same information. Objdump can be used to check
the header file is generated correctly. Embedding the code in gen_logic_imm in
test_insn.c would give less confidence that the encoder is doing the right thing.

This series is based on v5.17-rc1, and can be retrieved from:
https://git.gitlab.arm.com/linux-arm/linux-jm.git insn_encoder/fls_bug/v1

Thanks,

James Morse (3):
  arm64: selftests: Generate all the possible logical immediates as a
    header
  arm64: insn: Add tests for aarch64_insn_gen_logical_immediate()
  arm64: insn: Generate 64 bit mask immediates correctly

 arch/arm64/Kconfig.debug                   |   3 +
 arch/arm64/Makefile                        |   3 +
 arch/arm64/lib/Makefile                    |   2 +
 arch/arm64/lib/insn.c                      |   5 +-
 arch/arm64/lib/test_insn.c                 |  90 ++++++++++
 arch/arm64/tools/.gitignore                |   2 +
 arch/arm64/tools/Makefile                  |  12 +-
 arch/arm64/tools/gen_logic_imm.c           | 190 +++++++++++++++++++++
 tools/testing/selftests/arm64/Makefile     |   2 +-
 tools/testing/selftests/arm64/lib/Makefile |   6 +
 tools/testing/selftests/arm64/lib/config   |   1 +
 tools/testing/selftests/arm64/lib/insn.sh  |   5 +
 12 files changed, 318 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm64/lib/test_insn.c
 create mode 100644 arch/arm64/tools/.gitignore
 create mode 100644 arch/arm64/tools/gen_logic_imm.c
 create mode 100644 tools/testing/selftests/arm64/lib/Makefile
 create mode 100644 tools/testing/selftests/arm64/lib/config
 create mode 100755 tools/testing/selftests/arm64/lib/insn.sh

-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-15 23:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-27 16:21 [PATCH 0/3] arm64: insn: Generate 64 bit mask immediates correctly James Morse
2022-01-27 16:21 ` [PATCH 1/3] arm64: selftests: Generate all the possible logical immediates as a header James Morse
2022-01-28  2:47   ` kernel test robot
2022-01-27 16:21 ` [PATCH 2/3] arm64: insn: Add tests for aarch64_insn_gen_logical_immediate() James Morse
2022-02-15 15:55   ` Will Deacon
2022-01-27 16:21 ` [PATCH 3/3] arm64: insn: Generate 64 bit mask immediates correctly James Morse
2022-01-27 18:34   ` Marc Zyngier
2022-02-15 23:18 ` [PATCH 0/3] " Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).