From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Martin KaFai Lau <martin.lau@linux.dev>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
linux-crypto@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Mykola Lysenko <mykolal@fb.com>,
Vadim Fedorenko <vadfed@meta.com>,
"David S. Miller" <davem@davemloft.net>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: Re: [PATCH bpf-next v3 1/2] bpf: add skcipher API support to TC/XDP programs
Date: Thu, 2 Nov 2023 00:31:03 +0000 [thread overview]
Message-ID: <b07fbb30-92a5-7c96-339c-ffbdf40ea1bf@linux.dev> (raw)
In-Reply-To: <4adea710-72ca-0908-d280-625bc3682aa1@linux.dev>
On 01.11.2023 22:59, Martin KaFai Lau wrote:
> On 11/1/23 3:50 PM, Vadim Fedorenko wrote:
>>>> +static int bpf_crypto_skcipher_crypt(struct crypto_sync_skcipher *tfm,
>>>> + const struct bpf_dynptr_kern *src,
>>>> + struct bpf_dynptr_kern *dst,
>>>> + const struct bpf_dynptr_kern *iv,
>>>> + bool decrypt)
>>>> +{
>>>> + struct skcipher_request *req = NULL;
>>>> + struct scatterlist sgin, sgout;
>>>> + int err;
>>>> +
>>>> + if (crypto_sync_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
>>>> + return -EINVAL;
>>>> +
>>>> + if (__bpf_dynptr_is_rdonly(dst))
>>>> + return -EINVAL;
>>>> +
>>>> + if (!__bpf_dynptr_size(dst) || !__bpf_dynptr_size(src))
>>>> + return -EINVAL;
>>>> +
>>>> + if (__bpf_dynptr_size(iv) != crypto_sync_skcipher_ivsize(tfm))
>>>> + return -EINVAL;
>>>> +
>>>> + req = skcipher_request_alloc(&tfm->base, GFP_ATOMIC);
>>>
>>> Doing alloc per packet may kill performance. Is it possible to optimize it
>>> somehow? What is the usual size of the req (e.g. the example in the selftest)?
>>>
>>
>> In ktls code aead_request is allocated every time encryption is invoked, see
>> tls_decrypt_sg(), apparently per skb. Doesn't look like performance
>> killer. For selftest it's only sizeof(struct skcipher_request).
>
> ktls is doing the en/decrypt on the userspace behalf to compensate the cost.
>
> When this kfunc is used in xdp to decrypt a few bytes for each packet and then
> XDP_TX out, this extra alloc will be quite noticeable. If the size is usually
> small, can it be done in the stack memory?
Hmm... looks like SYNC_SKCIPHER_REQUEST_ON_STACK will help us. Ok, I'll change
this part to use stack allocations.
next prev parent reply other threads:[~2023-11-02 0:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 13:48 [PATCH bpf-next v3 1/2] bpf: add skcipher API support to TC/XDP programs Vadim Fedorenko
2023-10-31 13:49 ` [PATCH bpf-next v3 2/2] selftests: bpf: crypto skcipher algo selftests Vadim Fedorenko
2023-11-01 22:53 ` Martin KaFai Lau
2023-11-02 0:54 ` Vadim Fedorenko
2023-10-31 15:46 ` [PATCH bpf-next v3 1/2] bpf: add skcipher API support to TC/XDP programs Jiri Olsa
2023-10-31 15:58 ` Vadim Fedorenko
2023-11-01 21:49 ` Martin KaFai Lau
2023-11-01 22:50 ` Vadim Fedorenko
2023-11-01 22:59 ` Martin KaFai Lau
2023-11-02 0:31 ` Vadim Fedorenko [this message]
2023-11-01 23:41 ` Martin KaFai Lau
2023-11-02 0:38 ` Vadim Fedorenko
2023-11-02 13:44 ` Vadim Fedorenko
2023-11-02 15:36 ` Alexei Starovoitov
2023-11-02 16:14 ` Vadim Fedorenko
2023-11-02 17:47 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b07fbb30-92a5-7c96-339c-ffbdf40ea1bf@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=vadfed@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).