Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp45948imm; Thu, 30 Aug 2018 06:41:05 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZMWJA3FQSOvx4/egeqQWjmE59kU1Iiv7wEURgR1x01BSIqw9tnoOQyRafq9QZIRt6vj3xF X-Received: by 2002:a17:902:c85:: with SMTP id 5-v6mr10400269plt.141.1535636465729; Thu, 30 Aug 2018 06:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535636465; cv=none; d=google.com; s=arc-20160816; b=KOjrACnZw8oNdW4+ODr4r726TlBbF8+6kxWghTyaIMBxrDoerqVt5qLDdPYzXdVwrX CaV+lSUFFC0xE0kNQvsJyn+2JZf9cDdszjiYQ/za3mlLPPl2Lir3Sw8I/i4tCUXiKaYn Vp7NuwrDHAFjbFYYwtWvKGV2klUcqKixrQ3zidAz0RfpICf8Z6brWo/XKW+jHn6GIdDV QzPyewIXclGPTBRtFFdapcFHgkqvxeSML0JVZ8XQadIHIoCUYONrFBt1sgNs3C4yEsQo TmfOzvotA8b/pa0vGH7jtemE6FvwM1X9WJQJvwTKUASzmSdsvFXmjYtbbcfoZ7SuZvg+ 7TUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=I5X4B0R97iA61dCHIDo+VyG1rzOHQF+u9sHgIetHb3k=; b=P+t3UowxTUApKzkRawPhs5bAN+jhfv7P1DTSrIX+Ty38OL+zI2rF5/GVku2nmn0LeG YqvHpm6HIykfV1ak0RucXXBCy4wbQhDLUJ9TwXvqQDruqaYXL8RjQx8r11GU6rTrY2ZD 5AweU5NOCOkP9D4I7L33Y1Ep0JeyOrNNnvftXzXyNkpyodRs9yjjtvqH5DFHYPVN18vL AmA0UKcyMlLxZ+xLSmAo6sFSY7DMO1iRCklCasnv2VJbhxnU08lpAXJ0Xus9jm40wcNu avmKYl1V2hgsJqLYWiM0A++Z4Z9tFCWkan9piPn59XYXYXmb5KN2geZgKafhGlFbCQ42 BZgA== ARC-Authentication-Results: i=1; mx.google.com; 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 31-v6si6588386plg.260.2018.08.30.06.40.49; Thu, 30 Aug 2018 06:41:05 -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; 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 S1728998AbeH3Rlu (ORCPT + 99 others); Thu, 30 Aug 2018 13:41:50 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:54548 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728582AbeH3Rlu (ORCPT ); Thu, 30 Aug 2018 13:41:50 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1fvNAd-0006PL-2x; Thu, 30 Aug 2018 21:39:35 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fvNAZ-0005QQ-1r; Thu, 30 Aug 2018 21:39:31 +0800 Date: Thu, 30 Aug 2018 21:39:31 +0800 From: Herbert Xu To: Krzysztof Kozlowski Cc: "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, smueller@chronox.de Subject: Re: Locking for HW crypto accelerators Message-ID: <20180830133930.r7s5hmnriif46hlr@gondor.apana.org.au> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt