Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2870imm; Thu, 30 Aug 2018 07:03:02 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaQsQylRIIJUM7MkUoes6dXN2U9j4JS48AFeuK98VxtQBKmxK2e3p+81g4to5DJ5r1qFJB8 X-Received: by 2002:aa7:824d:: with SMTP id e13-v6mr10677646pfn.97.1535637782514; Thu, 30 Aug 2018 07:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535637782; cv=none; d=google.com; s=arc-20160816; b=lhtH417JOJaVDO0N0YLkWUOnfBxX+rfbvs0mgh4YmAHguAHpVEu/T/aq+o4XcHUEYh Bn73XQb+ERR8mtF8kIKcNFVlgp8SHhOWiWCK2z+x0YY/cD73v1zPWGZxeJNaRzSm5pRM SN613+q1xsq6WiEALP6GdAp8Sim+WELWFnBTmcBD99aG+SDakYQYz2EF6G4l1LUvLcQ0 4aUJq+TydQfmHx2+ebTVSMLBcwL/dgF9BN30gR2V8KubRyRdNTWpE/WjJuVSzvK4ikAm odFRo4pP0s452vEZmeWdUhi82GXUVeQgomEUbJphvRD3bH3U6dhxQdBQzB0DF+p0KDq9 tdog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=383R0U+1PBLI99D81z2vh1CUIqQKNGv5e7DkD+GAMrY=; b=Qbg1UcRF/KmNF+yNqO21uqNtMY86EEdtg89Qw6WwCEeB5fsKI4454dQUxzX1Kwi7iC 12eZgXufNaVYR7tTjlS6jwULBGXWh05taLd8o040txbuoXUcxKxVPQIBjjD3/hwalXYO vsQuWfPOWkahaacTp+Y/slScHFqoV3CXSyMlnPuGDflQCVogTVEAu1IOtDC+DrV/AAw1 cXj6hHJZkZJ10aYMaZ+54GV+y0G7rY5GSV27lQhCtBkKevp3U22fzyYu9W4o0KSKds4k fZJfq3fQW0FqrNnhmTJGQuoc1fOx6pmWeFcuRgYz4/0Xoc42I3ZXXnNz1QUQbB/ZYnbw 9Leg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KdGE7hpk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5-v6si6662918pfa.116.2018.08.30.07.02.42; Thu, 30 Aug 2018 07:03:02 -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=pass header.i=@kernel.org header.s=default header.b=KdGE7hpk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729140AbeH3SDP (ORCPT + 99 others); Thu, 30 Aug 2018 14:03:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:39170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728942AbeH3SDP (ORCPT ); Thu, 30 Aug 2018 14:03:15 -0400 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6D4EC20836; Thu, 30 Aug 2018 14:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535637658; bh=UMBXX+QKbwUh+grHbQZF+3Z2G5PHqHEIpQl5gfke3xM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KdGE7hpkwl5F/6GjoIHbFXPifEAdFfH8wCHP6po1eiXnbUYrMmwqs3sUFOJiDD4M+ nJcvj9UL1KemZj872QMBfnt6Vtvx+o6YlxpvQa+q++PbRUJFoNbw3K6e2n/uxSc21N 1rkeRsddv0EAzcGIQazmwtJWpE8c+qTPn9Z47n4k= Received: by mail-wr1-f51.google.com with SMTP id v90-v6so8194902wrc.0; Thu, 30 Aug 2018 07:00:58 -0700 (PDT) X-Gm-Message-State: APzg51CC6qYVhUOTo1Wlm9tMY1DWMGEUeMw9GaJQhDjh5PSH3345agny aENrAmw/t6AdX67+OrQSAdaAploObrSXtU92Lts= X-Received: by 2002:adf:cc91:: with SMTP id p17-v6mr7730728wrj.226.1535637656992; Thu, 30 Aug 2018 07:00:56 -0700 (PDT) MIME-Version: 1.0 References: <20180830133930.r7s5hmnriif46hlr@gondor.apana.org.au> In-Reply-To: <20180830133930.r7s5hmnriif46hlr@gondor.apana.org.au> From: Krzysztof Kozlowski Date: Thu, 30 Aug 2018 16:00:45 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Locking for HW crypto accelerators To: herbert@gondor.apana.org.au Cc: davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, smueller@chronox.de Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 30 Aug 2018 at 15:39, Herbert Xu wrote: > > On Thu, Aug 30, 2018 at 02:22:22PM +0200, Krzysztof Kozlowski wrote: > > 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... > > After each operation all state must be stored in the ahash_request > object. The next operation should then load the state from the > request object into the hardware. Thanks, that's the solution I was missing. Best regards, Krzysztof