From nobody Fri Aug 4 14:55:50 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RHTL01hdJz4TkM8; Fri, 4 Aug 2023 14:55:52 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RHTL018dGz3Mv9; Fri, 4 Aug 2023 14:55:52 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691160952; 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=Eikqwniskib4EfMJ7FVNqh51DaXqjA8jRpz04YBFqt4=; b=d/U29cNjbbuKpfKuFGn6x03+QwkdxkmuAxF21oc+q4mVTPr3CqYazrjScYH8JsuP3s8/Kc 16BM1C9oqFBsX85z6zWYDlHAU5iRd5FMdHgoJXncJ4Th/wp0rPHkQG2EMfmgocq5tcUnSC cR3mf4mOpbaiCQfzzC+lZhYI8M3IdFf0T+p2dKdWHxu/5y19L2ziANOk4sTyvmFYn24Fi6 Lp/kVtNCp91NaKP8XBDd4i65WPdUksT4AHzit5k3d+8fAt2iJHnuVjC79u/cPqX0p9Xr4d 8MvMm+tWyQfRZFz4QOeT9XCxXJ+3aN/o/DMcD5zixGBqWng61qVD3f0kbjduNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691160952; 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=Eikqwniskib4EfMJ7FVNqh51DaXqjA8jRpz04YBFqt4=; b=J8/hyZIBcFGGiEFLLDA3pFUmGtcTzWYg0ZV8dL0BbuaqnxzVM+F9k3BD5TjFrTeRTmH9ia VgGvKipc2aUTYMtjL8silwbWVDTxfsh/v6Tvk+lBKglP8iO01MYJ+0VyJdjMu+K8XswHmM dlHNTqaevurQzvl56RIx8Kl8phmIA6ZOM+OQW5ApDqizOq08mYxTqfUG/A3aQyyY0kz0eG z+H3LSGe/g1zlIGgDk1gojr1Sln6UFKOJucA4hNSP+zJTi1filjX+Myp82tbS6jQvoBJX/ gbNySyKKYnbDJU/kUU+wIM3BhCQxfJbJbNJAFd5FVg1k5j9RoSMKGsKTlJvCEA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691160952; a=rsa-sha256; cv=none; b=xHn3UwiuhTQ/CwVhuvWbgmdCybxAPReRXS7BrfOHewAir5np0kS3FKaivhh+Aw06tU4wL3 pnt6Q0HhumboQLspV9fs9FMNkhHtD15g2fnHozT3hTUWqms8fWje1bcVT3MyXVxLso6dDD jeWF5g78gZGccDJPiRNNfyZmRLYRr1Hb0XY10G4LB9SzvF7uiyV1cdxhsLV64zAKmC2qTk xFniAOzDRgbMPtfUd2kKidOJFyTeYDB5Bc9+si3yY+Lh7wjUg3z/Mml495hPgq7vEl3Fhp /hJShUxLnzFwQmz6Th61bgfkr4KsMd3m+WTSIClzyvw2ROGoqscOwIOgBq/01A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from [IPV6:2601:648:8680:16b0:cdd2:66b:dfd1:f731] (unknown [IPv6:2601:648:8680:16b0:cdd2:66b:dfd1:f731]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4RHTKz3YJqz11Nn; Fri, 4 Aug 2023 14:55:51 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Fri, 4 Aug 2023 07:55:50 -0700 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: Justin Hibbits , Shawn Anastasio Cc: freebsd-ppc@FreeBSD.org, freebsd-hackers@FreeBSD.org, Timothy Pearson References: <0c24b4b7-b4c8-242d-6187-15b171c50c19@raptorengineering.com> <20230804093605.2a61eeed@ralga.knownspace> From: John Baldwin Subject: Re: Implementing in-kernel AES crypto acceleration on ppc (POWER8+) In-Reply-To: <20230804093605.2a61eeed@ralga.knownspace> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 8/4/23 6:36 AM, Justin Hibbits wrote: > Hello, > > Good to see this! I'll answer inline. > > On Thu, 3 Aug 2023 12:51:57 -0500 > Shawn Anastasio wrote: > >> Hello all, >> >> Raptor Engineering is interested in adding support for in-kernel AES >> acceleration on ppc64 via the VMX crypto instructions added in ISA >> 2.07B, and I wanted to reach out to the community with a few >> questions. > > I would love to see this added. > >> >> 1. As I understand it, FreeBSD already has support for in-kernel >> crypto acceleration on x86 and ARM via the aesni and armv8_crypto >> drivers respectively that each implement the cryptodev interface. Am I >> correct in understanding that adding AES acceleration for Power >> would just involve creating another driver here, or are there other >> pieces of the puzzle that I've missed? > > John Baldwin can probably answer this better, but I think your > understanding is correct. There might be some plumbing needed as well, > but that should be minimal. Recently for accelerated software crypto we have been using the existing assembly routines from OpenSSL (which has ppc routines IIRC) in the ossl(4) driver. For powerpc you would need to provide any ppc-specific things the OpenSSL assembly routines need (e.g. on x86 they use an array of words holding feature bits corresponding to output from cpuid), and mostly just add build glue. This driver also requires fpu_kern_*, but in general ossl(4) is preferred going forward and will eventually replace aesni and armv8crypto entirely. >> 2. I see that both the aesni and armv8 drivers make use of the >> fpu_kern_enter/fpu_kern_leave functions to guard access to vector >> registers, but it appears that these functions aren't implemented >> on ppc. Is that correct, or does an in-kernel facility for safely >> accessing vector registers on ppc already exist? > > Nope, ppc doesn't have these facilities yet. It shouldn't be hard to > implement, we just haven't done it yet. If you're interested in > implementing them, you should be able to model it after arm64, largely. Yes, this is a prerequisite. If you implement this you can also enable assembly for ZFS on powerpc as well. >> 3. For the accelerated AES implementation itself, I've noticed that >> cryptogams[*] contains an implementation that is both widely >> deployed (and thus tested and likely to be correct) and also BSD >> licensed. Would it be acceptable to import the relevant routines to >> the FreeBSD kernel and have the new cryptodev driver simply call into >> them, or are there other considerations involved? > > I think the right way to do that would be to import the code as-is as > third party code, and call into the routines that you need. You can > #ifdef out the unneeded bits, but try to keep it as intact as possible > from upstream. As mentioned above, I would prefer using the OpenSSL sources already in the tree via ossl(4). >> 4. Is there a userspace test framework for the cryptodev API that >> could be used to validate and benchmark the new implementation, or >> would I have to write that myself? It appears that OpenSSL had >> support for /dev/crypto at one point, but I'm not sure that is the >> case any longer. > > John Baldwin might have some ideas here, too. There is a cryptocheck tool in tools/tools/crypto that I tend to use. It generates "random" but deterministic (since it uses a fixed seed for libc's PRNG) tests of most of the algorithms supported by the cryptodev API with various key sizes, nonce sizes, payload, and AAD sizes. It performs each test once with OpenSSL's userland crypto and a second time with /dev/crypto and compares the results reporting any mismatches. There isn't a manpage, but there are some comments in the source. There are also some tests in the test suite that make use of the NIST known answer test vectors (which have to be installed via a nist-kat package). -- John Baldwin