Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp32664rdb; Wed, 1 Nov 2023 16:00:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUkf6rQFHk5bui7sUm8X9JpYxD6perhn0ffuxhsKTTosyh7u3pCAbePDt9T8gPkcrpnECy X-Received: by 2002:a05:6a00:c8f:b0:6b8:780:94e5 with SMTP id a15-20020a056a000c8f00b006b8078094e5mr17666250pfv.18.1698879641842; Wed, 01 Nov 2023 16:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698879641; cv=none; d=google.com; s=arc-20160816; b=S1Yd9dyqCGYq8p15F9bsfpZ3ZDEvDdAbNJb9FU5QzoWwunoxaUhBWVMnJHTSMPFpxP Nqj3neKjKwEgtanvynx5rXbRge7QWhxS+LQMsScnwS3GPGvKlG6mSLnmc1pL13UQGbz8 nYi5vvRaxTt8khJRvOdBd+KLawXXftqeHgN+3p4DE4qfl+L8ZI/zbVj9r5589GqOR7Jr 3iPWXasOThEYy98snoU9htXhv43UJgKsb5Dt1TYs29gOi9wmv09fOsq+YRfhRSaaFJug McGTeGiChA6/zVBaSgokaoStLI3qSPHMMpCjq3LpRVEhZGdCUP9xPF7zv5624jxdw19w gRhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=4sqmgjsG0HKRXnINDdYX/GSWOxBGCUrEHbZ1VjS0FC4=; fh=TdZMYNnTdW87gOUJKCGEmiOjD4VCdlCFIwIs4xkwkBo=; b=KN2iZ1AdEv81pcYwTGYiVBX0FXk8rm8utkw/YsV+YFEKib80L/Q0x4oJ5LNERHQWz1 DGAYwicsMjS0QUErCxtROGKFi8Hn+qQ65eTczN2OKHXFXoRQ0LFe9H7tJD5f7oEzWLub zGYcgNaYy+qorPk93OBNtcNG4D5uIr+g2XS8bHr5ZvW6FZygLudTFBn5PWR4E+EBPebr rfD0wS++txk4XLjFTVy5N3ct5Wac9wWlq4OhMagLAUjUKZFrpiK3ZLtRVzpG5WKarcpq 7RmZGZR8U6GSdH2P4+jjsXpzehvt2rry2/RmVS01NWwBHYci6+hfsa/UMYytWqF2wvPb WECw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UeXfnVc5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j2-20020a056a00174200b006bd018a5bcfsi2723394pfc.340.2023.11.01.16.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 16:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=UeXfnVc5; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 24319809AFDA; Wed, 1 Nov 2023 16:00:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232861AbjKAXAI (ORCPT + 99 others); Wed, 1 Nov 2023 19:00:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232330AbjKAXAI (ORCPT ); Wed, 1 Nov 2023 19:00:08 -0400 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1F48C1; Wed, 1 Nov 2023 16:00:02 -0700 (PDT) Message-ID: <4adea710-72ca-0908-d280-625bc3682aa1@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698879600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4sqmgjsG0HKRXnINDdYX/GSWOxBGCUrEHbZ1VjS0FC4=; b=UeXfnVc5fsyHfh7/ucNFUm88AL8HoePIFTrZsJJLU1YbNBrHxbwRAyHXUiSu5/xXrVGsI4 ZFs14FsopunycDLUKVS17m9wafWnjM7KVC2PYGN6Rzzz2T4ffkXqkpi057NtyHdYLq0N9W GrZagU6f2MplQdgw/ZVciLirdx3ggKQ= Date: Wed, 1 Nov 2023 15:59:56 -0700 MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v3 1/2] bpf: add skcipher API support to TC/XDP programs Content-Language: en-US To: Vadim Fedorenko Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, linux-crypto@vger.kernel.org, Jakub Kicinski , Andrii Nakryiko , Alexei Starovoitov , Mykola Lysenko , Vadim Fedorenko , "David S. Miller" , Herbert Xu References: <20231031134900.1432945-1-vadfed@meta.com> <91a6d5a7-7b18-48a2-9a74-7c00509467f8@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <91a6d5a7-7b18-48a2-9a74-7c00509467f8@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 01 Nov 2023 16:00:18 -0700 (PDT) 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?