Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf, mips: No need to use min() to get MAX_TAIL_CALL_CNT

MAX_TAIL_CALL_CNT is 33, so min(MAX_TAIL_CALL_CNT, 0xffff) is always
MAX_TAIL_CALL_CNT, it is better to use MAX_TAIL_CALL_CNT directly.

At the same time, add BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff) with a
comment on why the assertion is there.

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/1661742309-2320-1-git-send-email-yangtiezhu@loongson.cn

authored by

Tiezhu Yang and committed by
Daniel Borkmann
bbcf0f55 aa75622c

+18 -2
+9 -1
arch/mips/net/bpf_jit_comp32.c
··· 1377 1377 int stack, saved, locals, reserved; 1378 1378 1379 1379 /* 1380 + * In the unlikely event that the TCC limit is raised to more 1381 + * than 16 bits, it is clamped to the maximum value allowed for 1382 + * the generated code (0xffff). It is better fail to compile 1383 + * instead of degrading gracefully. 1384 + */ 1385 + BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff); 1386 + 1387 + /* 1380 1388 * The first two instructions initialize TCC in the reserved (for us) 1381 1389 * 16-byte area in the parent's stack frame. On a tail call, the 1382 1390 * calling function jumps into the prologue after these instructions. 1383 1391 */ 1384 - emit(ctx, ori, MIPS_R_T9, MIPS_R_ZERO, min(MAX_TAIL_CALL_CNT, 0xffff)); 1392 + emit(ctx, ori, MIPS_R_T9, MIPS_R_ZERO, MAX_TAIL_CALL_CNT); 1385 1393 emit(ctx, sw, MIPS_R_T9, 0, MIPS_R_SP); 1386 1394 1387 1395 /*
+9 -1
arch/mips/net/bpf_jit_comp64.c
··· 548 548 int stack, saved, locals, reserved; 549 549 550 550 /* 551 + * In the unlikely event that the TCC limit is raised to more 552 + * than 16 bits, it is clamped to the maximum value allowed for 553 + * the generated code (0xffff). It is better fail to compile 554 + * instead of degrading gracefully. 555 + */ 556 + BUILD_BUG_ON(MAX_TAIL_CALL_CNT > 0xffff); 557 + 558 + /* 551 559 * The first instruction initializes the tail call count register. 552 560 * On a tail call, the calling function jumps into the prologue 553 561 * after this instruction. 554 562 */ 555 - emit(ctx, ori, tc, MIPS_R_ZERO, min(MAX_TAIL_CALL_CNT, 0xffff)); 563 + emit(ctx, ori, tc, MIPS_R_ZERO, MAX_TAIL_CALL_CNT); 556 564 557 565 /* === Entry-point for tail calls === */ 558 566