Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp746352pxb; Wed, 25 Aug 2021 14:07:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3MqdrOOVHB9GpS2/tsfiQ8PamfmK8ZixlhJcj7YJOWmoQSV4Ct9cHXJuecK2VfFDk1rd5 X-Received: by 2002:a5d:974f:: with SMTP id c15mr352782ioo.190.1629925651136; Wed, 25 Aug 2021 14:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629925651; cv=none; d=google.com; s=arc-20160816; b=iNv0sEzPQj/F87qEk4XgC7WD4yOAma6wNF8AUGUmjrKVpMhWbAVTIAK/2M64yPP6FD wEl53mLhxpsO2d9nLSSeDqsdwNH3Yh8plNX5Mfv/RJX0BBDRk3dti1KtHx6fa9LvGi/W 8fXUO8ULpp5Iy61DTXcOoDwXAfqMqhGxHJfU8xF/tYaU3ioJWdFifkJy3GocsAK5ngIA PZHmB9/Eh9EvFti4TI2PlV4P7eniv35h1sCejPNQxZ/DidqZaSe5hzhHat1zkb9P6PuX /+l1XQdWGIGYA4lzMpMBA6ELJ4DzCBYpu16kCCp4ulY58PZTx4sOST0M3Lxq8Hch6N7z MWMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=xvawx26XH1LgAnwFO6bkrCV07A1Wb2tVA3/Wjwf9oRQ=; b=YkHGw9J7gXXZ//JXjVYDHj7FxXLoCb7l48Rf7anMcjMwWMXzDEP+KN0iR+WKO7owJb f6M+Y7bDNX28xs2FjSxtRlhngsf4UHocsdHkGWWhtKQFkTPR6oT6C9O93q3EtBkqj82Q 8tQs+PeKTzb5MBiAY7YBtsiWifHwPONGkwpIBtXwxAvKMNBbTyE5/smuo4m7JdNCroc+ 9R3yMUCfmEs8oW4Yt0vp2pBA1KIKIenO4VDYtoy/ghfHamedMi5ruYoMUie+L5ozDAth Jn+q2aMU3C4P5ZCUfcj1gJ59N7tD9oBxsX+1MMJEh+/u0Znd46LWH66PkgLcbrzDo3qS 37wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OEeSzujy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si1062968iov.41.2021.08.25.14.07.12; Wed, 25 Aug 2021 14:07:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OEeSzujy; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235825AbhHYS5H (ORCPT + 99 others); Wed, 25 Aug 2021 14:57:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235732AbhHYS5H (ORCPT ); Wed, 25 Aug 2021 14:57:07 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 450C8C061757; Wed, 25 Aug 2021 11:56:21 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id mf2so510400ejb.9; Wed, 25 Aug 2021 11:56:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=xvawx26XH1LgAnwFO6bkrCV07A1Wb2tVA3/Wjwf9oRQ=; b=OEeSzujyOV65sqIdM5kYmWTYcqidPsldWKX79B3NxqL4aMp6dfU7LRu+/VYaO3NwQB LIw51AnkVRjthkcsR1EONmLe/N/Jp9RhzMCuhfEdAKWQgIlnJuGUxuE7Ruq8Y4NGeybD zCoa0MSY1k3gAIeFQ0ELLZVrfxxSpKXu470fadvRWCNm9/U/I5Gbd6ZtJYroZIrKvHEr +yzXg19h2Qc1lDOcx66x6HrvJ96GbgUB3QTGp6h3k8uomIH3AwD/wUS+mPz2Lx3gdYUW meZyoHddVqUr+5LVnzYal6g6i8usJ121xGfz8v1P6uLIBHy6IIRijD9Yj4zHPsKgl4aV nHdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=xvawx26XH1LgAnwFO6bkrCV07A1Wb2tVA3/Wjwf9oRQ=; b=n9Zp/Z1TDfBtDt7C2bC0sctpD7PUvoNP+1dmls1hVu8IFMK025zzkMIyqaSwsHDz7I 7XoXbgvuPdMMXXlT0Gn0K6kqHWy0uRqrtzGkwv4rHTqm/ZXJ0RglHtvbNMO6+T7tm83N QssN7zxsRbsMY5vmvbd6qBsdktpVAYEhitAHLQmYbCIoWuX6Dj+3hrOGUPGH39AkF4Cg Bz6BwTmD4mn5H133gBEsjGMCrHGpuCcoyB4htQspa1oEunW7jnAvMVpVgrz9eULtRPx9 FPklbi++X1z0ou8oBwLxD6cnPGGL52I6tIl785p66ftSjtZCjM3A+MHBpa2tMF/8LWt0 MJZg== X-Gm-Message-State: AOAM532Qx+VAyeYTMbiJoQkQ28GHeQgWXsjUOtKvM/z7b5mtPENjqGpH BmUdYRFsfg0PmSvLCqtLXwDgARZtzuE7YQ== X-Received: by 2002:a17:906:a0da:: with SMTP id bh26mr73147ejb.505.1629917779776; Wed, 25 Aug 2021 11:56:19 -0700 (PDT) Received: from ?IPv6:2a04:241e:502:1d80:f02c:a1bd:70b1:fe95? ([2a04:241e:502:1d80:f02c:a1bd:70b1:fe95]) by smtp.gmail.com with ESMTPSA id e7sm517874edk.3.2021.08.25.11.56.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Aug 2021 11:56:19 -0700 (PDT) Subject: Re: [RFCv3 05/15] tcp: authopt: Add crypto initialization To: Eric Dumazet , Herbert Xu Cc: Eric Dumazet , Dmitry Safonov <0x7f454c46@gmail.com>, David Ahern , "David S. Miller" , Kuniyuki Iwashima , Hideaki YOSHIFUJI , Jakub Kicinski , Yuchung Cheng , Francesco Ruggeri , Mat Martineau , Christoph Paasch , Ivan Delalande , Priyaranjan Jha , Menglong Dong , netdev , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , "open list:KERNEL SELFTEST FRAMEWORK" , LKML , Shuah Khan References: <30f73293-ea03-d18f-d923-0cf499d4b208@gmail.com> <27e56f61-3267-de50-0d49-5fcfc59af93c@gmail.com> From: Leonard Crestez Message-ID: <9ee51fc2-0b7e-4dc5-881b-9f6d671347ea@gmail.com> Date: Wed, 25 Aug 2021 21:56:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 8/25/21 8:55 PM, Eric Dumazet wrote: > On Wed, Aug 25, 2021 at 9:35 AM Leonard Crestez wrote: >> >> On 25.08.2021 02:34, Eric Dumazet wrote: >>> On 8/24/21 2:34 PM, Leonard Crestez wrote: >>>> The crypto_shash API is used in order to compute packet signatures. The >>>> API comes with several unfortunate limitations: >>>> >>>> 1) Allocating a crypto_shash can sleep and must be done in user context. >>>> 2) Packet signatures must be computed in softirq context >>>> 3) Packet signatures use dynamic "traffic keys" which require exclusive >>>> access to crypto_shash for crypto_setkey. >>>> >>>> The solution is to allocate one crypto_shash for each possible cpu for >>>> each algorithm at setsockopt time. The per-cpu tfm is then borrowed from >>>> softirq context, signatures are computed and the tfm is returned. >>>> >>> >>> I could not see the per-cpu stuff that you mention in the changelog. >> >> That's a little embarrasing, I forgot to implement the actual per-cpu >> stuff. tcp_authopt_alg_imp.tfm is meant to be an array up to NR_CPUS and >> tcp_authopt_alg_get_tfm needs no locking other than preempt_disable >> (which should already be the case). > > Well, do not use arrays of NR_CPUS and instead use normal per_cpu > accessors (as in __tcp_alloc_md5sig_pool) > >> >> The reference counting would still only happen from very few places: >> setsockopt, close and openreq. This would only impact request/response >> traffic and relatively little. > > What I meant is that __tcp_alloc_md5sig_pool() allocates stuff one time, > we do not care about tcp_md5sig_pool_populated going back to false. > > Otherwise, a single user application constantly allocating a socket, > enabling MD5 (or authopt), then closing the socket would incur > a big cost on hosts with a lot of cpus. Allocating only once would definitely simply things. I don't know if this might end up tying hardware resources forever if some accelerators are in play but for this feature software-only crypto is perfectly fine. -- Regards, Leonard