Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp15669imm; Thu, 30 Aug 2018 06:01:12 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda2+OIUIZip7EftWt/18LbA73cxq5dR4KlHj5OaCvI30Yz/MVUFzlGdLH0vpotl0TBXzOnS X-Received: by 2002:a62:c182:: with SMTP id i124-v6mr10309172pfg.248.1535634072832; Thu, 30 Aug 2018 06:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535634072; cv=none; d=google.com; s=arc-20160816; b=LNIb4gofLxB3xPlA3psmOPM+nwNWng1jHr5qsoAu7DbPk9/o+7iZ9n1SDPO0QrPajf WBvvp3PpSdGq73vBilvDmkMs2ft8kIVInlJu/yqRHavZcrJcMc6mfmL++SVQ+SNT+31v IdTfFabXotenkXMRsW5yMzevOlFVco5t3DbwLSPoQQnxi1p+coqrCElNi7R7Aq89ccVe yaCmWvDXglYFB5Tqt5jjyfTxkjphJxXuT78WnEiMwGDxeyEU6p8Adv3LoCm+VFw3MNLp RFAN7qgxIZ8KOm8y2GiGkOXiWJoPcUljkKHC29CHsqbN1yuQqqKHyQ7Tpeh0KBz8E8ZF w5OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=3YPU515KjwZS3K4Fkd8NRjgkOQW1EcQEfZybFhiBmFs=; b=aO4OsTRRIGi5E6Q3KQTvZK3DDzNFJmLIuFCyWIxlQjcE+E86VYm7wu1GbBhN9sikU0 vgAci9mAVPyo8OHlQuFz1pcZtbPJNA22g4sWL08n4SlXKAqHY2lqkzg/wXgd9f9kbRLy e4+C2Uz79JOTMTYghhQDPVIYKf+sJerOKOgTHaKLErfmtv9YrKenmUTUID+OUdmKF6Jj WN4AG7tqj4GiGMHt90opXKA6UUj4l5hWlzcWSxXCGoEKTtlF3KXmG7YFRFomkGqkBc0X ME/KAJr6lm810C98itBK5iULAYj6qtqy0I31Z6pdJClQILsbbqLZDkha7HCVvivw1T6c 89QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chronox.de header.s=strato-dkim-0002 header.b="Hiu7BHB/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7-v6si5831577pgh.595.2018.08.30.06.00.56; Thu, 30 Aug 2018 06:01:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chronox.de header.s=strato-dkim-0002 header.b="Hiu7BHB/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728911AbeH3RBF (ORCPT + 99 others); Thu, 30 Aug 2018 13:01:05 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.22]:16610 "EHLO mo4-p00-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728638AbeH3RBF (ORCPT ); Thu, 30 Aug 2018 13:01:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1535633942; s=strato-dkim-0002; d=chronox.de; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=3YPU515KjwZS3K4Fkd8NRjgkOQW1EcQEfZybFhiBmFs=; b=Hiu7BHB/jUbCysV1cH/ICkNfqCzD8MM4WKi7AmK9rY8d+/FvqAvXUAaxaYLMvhYqXh mroducwxQ3gA1IOq0vyBM+iCi0T4sINc90G4mB3AowKsZgbYJh/crDVOU2912WT4ye2n qOuytL3fTF6tZC5mDcT96kAw94ONhfPkhl79ZJZ/uyzusg3WRbpzf83kUx6gi8EDw6In zhspR9O8Bfj/hqMUyIBdeUXDfjYoPlgKxCRdAliJ5y5igO3DGDYjZD9eWpBe6cTsb9ed 6K43wVoq+eT/U1hkU7wWWUuCp8IFQALPmWdVVA8TieTu9rUS0nsyVUHajz+2jquF3JDI s1WQ== X-RZG-AUTH: ":P2ERcEykfu11Y98lp/T7+hdri+uKZK8TKWEqNyiHySGSa9k9xmwdNnzGHXPaIfSfABn3" X-RZG-CLASS-ID: mo00 Received: from tauon.chronox.de by smtp.strato.de (RZmta 43.21 DYNA|AUTH) with ESMTPSA id e08f60u7UCu2HU6 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 30 Aug 2018 14:56:02 +0200 (CEST) From: Stephan Mueller To: Krzysztof Kozlowski Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Locking for HW crypto accelerators Date: Thu, 30 Aug 2018 14:56:01 +0200 Message-ID: <3053033.se6UkFii4W@tauon.chronox.de> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Donnerstag, 30. August 2018, 14:22:22 CEST schrieb Krzysztof Kozlowski: Hi Krzysztof, > Hi, > > I am trying to figure out necessary locking on the driver side of > crypto HW accelerator for symmetric hash (actually: CRC). I > implemented quite simple driver for shash_alg. > > I looked at the docs, I looked at the crypto kcapi core code... and > there is nothing about necessary locking. kcapi does not perform it. > > My HW is quite similar to drivers/crypto/stm32/stm32_crc32.c so it has > only one HW set of registers for dealing with CRC. Or in other words, > only one queue of one element. :) I implemented all shash_alg > callbacks - init(), update(), final()... and also finup() (manually > calling update+final) and digest() (init+update+final). > > Now imagine multiple user-space users of this crypto alg where all of > them call kcapi_md_digest() (so essentially init() -> update() -> > final()). It seems that kcapi does not perform any locking here so at > some point updates from different processes might be mixed with > finals: > > Process A: Process B: > init() > init() > update() > update() > final() > final() > > My findings show that the requests are indeed being mixed with each other... > > Should driver perform any weird locking here? Or maybe that is the > case of using ONLY the digest() callback (so no update, no final) > because my HW cannot track different kcapi requests? The hashing is performed on a buffer provided by the caller. E.g. it is the buffer pointed to by the ahash request or the shash desc structure. All operations of init/update/final operate on that memory. If you have parallel requests, each caller has a private buffer that it provides to the kernel crypto API. This applies also to AF_ALG. Thus, as long as the individual operations of init/update and final are atomic operations, there should be no locking necessary. Thus, all your driver needs to guarantee is the atomicitcy of the init/update/ final operation in respect to your hardware state. Ciao Stephan