]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Fix subreg optimization for BPF_FETCH
authorIlya Leoshkevich <iii@linux.ibm.com>
Wed, 10 Feb 2021 20:45:02 +0000 (21:45 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 12 Feb 2021 06:03:19 +0000 (22:03 -0800)
commitf5282bc046def9280f283ab761afebb852aa1de2
treef73cb840add63bc77b4b4e435b25dcb9d0d74a0b
parentaaf4c6f4c0794642eaeafa9b54876558375fc3be
bpf: Fix subreg optimization for BPF_FETCH

All 32-bit variants of BPF_FETCH (add, and, or, xor, xchg, cmpxchg)
define a 32-bit subreg and thus have zext_dst set. Their encoding,
however, uses dst_reg field as a base register, which causes
opt_subreg_zext_lo32_rnd_hi32() to zero-extend said base register
instead of the one the insn really defines (r0 or src_reg).

Fix by properly choosing a register being defined, similar to how
check_atomic() already does that.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210210204502.83429-1-iii@linux.ibm.com
kernel/bpf/verifier.c