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

selftests: bpf: crypto: adjust bench to use nullable IV

The bench shows some improvements, around 4% faster on decrypt.

Before:

Benchmark 'crypto-decrypt' started.
Iter 0 (325.719us): hits 5.105M/s ( 5.105M/prod), drops 0.000M/s, total operations 5.105M/s
Iter 1 (-17.295us): hits 5.224M/s ( 5.224M/prod), drops 0.000M/s, total operations 5.224M/s
Iter 2 ( 5.504us): hits 4.630M/s ( 4.630M/prod), drops 0.000M/s, total operations 4.630M/s
Iter 3 ( 9.239us): hits 5.148M/s ( 5.148M/prod), drops 0.000M/s, total operations 5.148M/s
Iter 4 ( 37.885us): hits 5.198M/s ( 5.198M/prod), drops 0.000M/s, total operations 5.198M/s
Iter 5 (-53.282us): hits 5.167M/s ( 5.167M/prod), drops 0.000M/s, total operations 5.167M/s
Iter 6 (-17.809us): hits 5.186M/s ( 5.186M/prod), drops 0.000M/s, total operations 5.186M/s
Summary: hits 5.092 ± 0.228M/s ( 5.092M/prod), drops 0.000 ±0.000M/s, total operations 5.092 ± 0.228M/s

After:

Benchmark 'crypto-decrypt' started.
Iter 0 (268.912us): hits 5.312M/s ( 5.312M/prod), drops 0.000M/s, total operations 5.312M/s
Iter 1 (124.869us): hits 5.354M/s ( 5.354M/prod), drops 0.000M/s, total operations 5.354M/s
Iter 2 (-36.801us): hits 5.334M/s ( 5.334M/prod), drops 0.000M/s, total operations 5.334M/s
Iter 3 (254.628us): hits 5.334M/s ( 5.334M/prod), drops 0.000M/s, total operations 5.334M/s
Iter 4 (-77.691us): hits 5.275M/s ( 5.275M/prod), drops 0.000M/s, total operations 5.275M/s
Iter 5 (-164.510us): hits 5.313M/s ( 5.313M/prod), drops 0.000M/s, total operations 5.313M/s
Iter 6 (-81.376us): hits 5.346M/s ( 5.346M/prod), drops 0.000M/s, total operations 5.346M/s
Summary: hits 5.326 ± 0.029M/s ( 5.326M/prod), drops 0.000 ±0.000M/s, total operations 5.326 ± 0.029M/s

Reviewed-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
Link: https://lore.kernel.org/r/20240613211817.1551967-5-vadfed@meta.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Vadim Fedorenko and committed by
Alexei Starovoitov
9b560751 9363dc8d

+4 -6
+4 -6
tools/testing/selftests/bpf/progs/crypto_bench.c
··· 57 57 { 58 58 struct __crypto_ctx_value *v; 59 59 struct bpf_crypto_ctx *ctx; 60 - struct bpf_dynptr psrc, pdst, iv; 60 + struct bpf_dynptr psrc, pdst; 61 61 62 62 v = crypto_ctx_value_lookup(); 63 63 if (!v) { ··· 73 73 74 74 bpf_dynptr_from_skb(skb, 0, &psrc); 75 75 bpf_dynptr_from_mem(dst, len, 0, &pdst); 76 - bpf_dynptr_from_mem(dst, 0, 0, &iv); 77 76 78 - status = bpf_crypto_encrypt(ctx, &psrc, &pdst, &iv); 77 + status = bpf_crypto_encrypt(ctx, &psrc, &pdst, NULL); 79 78 __sync_add_and_fetch(&hits, 1); 80 79 81 80 return 0; ··· 83 84 SEC("tc") 84 85 int crypto_decrypt(struct __sk_buff *skb) 85 86 { 86 - struct bpf_dynptr psrc, pdst, iv; 87 + struct bpf_dynptr psrc, pdst; 87 88 struct __crypto_ctx_value *v; 88 89 struct bpf_crypto_ctx *ctx; 89 90 ··· 97 98 98 99 bpf_dynptr_from_skb(skb, 0, &psrc); 99 100 bpf_dynptr_from_mem(dst, len, 0, &pdst); 100 - bpf_dynptr_from_mem(dst, 0, 0, &iv); 101 101 102 - status = bpf_crypto_decrypt(ctx, &psrc, &pdst, &iv); 102 + status = bpf_crypto_decrypt(ctx, &psrc, &pdst, NULL); 103 103 __sync_add_and_fetch(&hits, 1); 104 104 105 105 return 0;