From owner-freebsd-current@freebsd.org Thu Mar 11 22:55:01 2021 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9877F5AEF09 for ; Thu, 11 Mar 2021 22:55:01 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DxPR93tJ4z4VmB; Thu, 11 Mar 2021 22:55:01 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-oi1-f170.google.com with SMTP id d16so15618882oic.0; Thu, 11 Mar 2021 14:55:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ckrV9/SyQXos2J5iZnodzjC2qsCcXn41sj1CsoLggOI=; b=EW4dylbJQS2lV+LB+KVHVKzn1qunivRh4viCQgBFjKilBRC9GiSuXSpHe6DvGWwXT7 9rivnUoL2yEvsapH/yOmQu2PtFLPLK7O+58GUtXUHpRrxxahlSJQslV4Z5Nq36CNFgQ2 DUpT3K1IBtmmell+gH4DUW6ak0Fj7FPn6QIabkmRQVpZ1MYY0A+Gvaw7rkUqvtEwOqXU Ix9C4uWmVt+xslXNaeJRpBL74fr5N3QKCN0XOhOeXAZow+31oAg973kJ7Kafmui6XC8s 7JxCIboICONi+MyTnZJlNb4rrXL5RIyseIuyTc4PLYLBybFrN4irOw7859B358KoXDUJ LBdg== X-Gm-Message-State: AOAM5334TG2nvcha1Z1EApfcKJOLMQGl4iISTv1ayM7Jlvos1PqcuB/U k+hYKF+u9WCmuaRHdWwEOnXgbwqTqiB/waqYOkGsYRPV9791eg== X-Google-Smtp-Source: ABdhPJyES2sfu5afxAGO6wJLAsfneW8xIQ8KlapF/F6IQWP6FNxBeWeyPxkchTIYlFxgV2iJlb38q+yEGEpimCIZ9+U= X-Received: by 2002:aca:4f0b:: with SMTP id d11mr8178107oib.73.1615503300133; Thu, 11 Mar 2021 14:55:00 -0800 (PST) MIME-Version: 1.0 References: <24d697e1-1232-7b53-923c-5ba39c6d8d80@FreeBSD.org> In-Reply-To: <24d697e1-1232-7b53-923c-5ba39c6d8d80@FreeBSD.org> From: Alan Somers Date: Thu, 11 Mar 2021 15:54:48 -0700 Message-ID: Subject: Re: Getting started with ktls To: John Baldwin , Rick Macklem Cc: FreeBSD CURRENT X-Rspamd-Queue-Id: 4DxPR93tJ4z4VmB X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.34 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Mar 2021 22:55:01 -0000 On Thu, Mar 11, 2021 at 11:49 AM John Baldwin wrote: > On 3/10/21 4:18 PM, Alan Somers wrote: > > I'm trying to make ktls work with "zfs send/recv" to substantially reduce > > the CPU utilization of applications like zrepl. But I have a few > questions: > > > > * ktls(4)'s "Transmit" section says "Once TLS transmit is enabled by a > > successful set of the TCP_TXTLS_ENABLE socket option", but the "Supported > > Libraries" section says "Applications using a supported library should > > generally work with ktls without any changes". These sentences seem to > be > > contradictory. I think it means that the TCP_TXTLS_ENABLE option is > > necessary, but OpenSSL sets it automatically? > > Yes, you can do it by hand if you want but you'd have to do all the key > exchange by hand as well. > > > * When using OpenSSL, the library will automatically call setsockopt(_, > > TCP_TXTLS_ENABLE). But it swallows the error, if any. How is an > > application to tell if ktls is enabled on a particular socket or OpenSSL > > session? > > BIO_get_ktls_send() and BIO_get_ktls_recv() on the write and read BIO's of > the connection, respectively. > > > * From experiment, I can see that OpenSSL attempts to set > > TCP_TXTLS_ENABLE. But it doesn't try to set TCP_RXTLS_ENABLE. Why not? > > From reading ktls_start and ossl_statem_server_post_work, it looks like > > maybe a single socket cannot have ktls enabled for both sending and > > receiving at the same time. Is that true? > > Neither FreeBSD nor OpenSSL yet support RX offload on TLS 1.3. If you use > TLS 1.2 you will get KTLS in both directions (or if you use TLS 1.1 with > TOE offload on a Chelsio T6). > > -- > John Baldwin > Switching to TLS 1.2 turned out to be key. Once I did that, ... it just worked. I was expecting to need minor changes throughout the kernel and libzfs. However, that wasn't necessary. Here is my proof-of-concept program. So far only the recv path is implemented. I'll probably implement the send path too, but I'm not currently planning to integrate this into any open-source application. Thanks for all the help! https://github.com/asomers/freebsd-src/tree/ktls-zfs/tools/zfs-ktls -Alan