Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp538301imm; Thu, 30 Aug 2018 05:24:10 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda4Id3H3zC7xFe25JnzrYHW1C2mhLmpalA/5XO7IMhKquCSlsWmWxgtTEYJSWAtkU2FHgve X-Received: by 2002:a63:6183:: with SMTP id v125-v6mr9775791pgb.242.1535631849914; Thu, 30 Aug 2018 05:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535631849; cv=none; d=google.com; s=arc-20160816; b=cvGgfHRgeWnfKTemUBWqhL2lARWy37jJQFWi4ol0xR7HsneSBsW+MIXlJliibjtPzu QfaPWz6jrYd86B2ZvDAUAEhNZHQam73m6vrM0kHn2eqWrO+A5V7pLPHUsf9l5fcI/See 8jBjTYbSTwi1OrT9DjbzI4tF2bdo0poVpT4Dvy0u0aiomC3YBgK3PYTXMGmmNFruhQ8H tJUdyxvLNU9jQowba8PL1vahw+OLkwUHFlB+HSkTh81Vy4d/cyEsg483fSPdXhrTyjJE uZD+F62ytB5l5ew1gzuU9V44IkjsF9VYT9g/Xtmf81QuZHjzYF+WQ43U7WM3CtTDnyT4 Iaxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :mime-version:dkim-signature:arc-authentication-results; bh=aLbfAp2sgDKhlbhzzV5K+PLlPfpdGiB+1KqT2qUq24k=; b=uNlMVt0l/fRy3cpv1PIknw9EH54OyF5KzWnq+7qPYQxqC6D0hkcvioCrVlp9YmPhaV +nyHA5dAvdNoGeoszL0HroELYewv0aJIuE8UPXAVRkBftNHNczJVIojP/u8Q/WshYlMO 6r26S+jliBiLKFUC1xjnvOZdKGbuLYK2BlP9LAEe9suy0t4T1Tk9JYh1YMIBmyBRATY1 JrLFg4LdupnNhrve2pUnWnm7XewHC0BHanOEWFcMQZRvvdcIW8xuQAXkSDvHbGFCpeRw 3ytRZYijTB26oFlXAOjU1AVzwurBitvTDWbXYsUxrgyzZVdzj2Efmsya68FD7SL1EAKQ nOFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1vF7c//5"; 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 v21-v6si6340145plo.397.2018.08.30.05.23.55; Thu, 30 Aug 2018 05:24:09 -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="1vF7c//5"; 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 S1728802AbeH3QY3 (ORCPT + 99 others); Thu, 30 Aug 2018 12:24:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:54798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728441AbeH3QY3 (ORCPT ); Thu, 30 Aug 2018 12:24:29 -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 550B720835; Thu, 30 Aug 2018 12:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535631755; bh=kx93GrFcBPvCaooof/mjkFoZx15gJ+/IuqHVIGP48tQ=; h=From:Date:Subject:To:From; b=1vF7c//5fxioUm/QpmMwvANq+xD2nAttU+zvdOFfQWfEqAl8ubNAKKl2BkyzmM+dK 3Pl+rn8jy4xBh5tJphoKgMJvxYyfozIArV7s+CcVi+us8Et3Ae7XjpaBn+J4/+Go45 zom0eVQl9esa0AaSVY+V5xyk41j+RCf6YkpULchc= Received: by mail-wr1-f51.google.com with SMTP id j26-v6so7884597wre.2; Thu, 30 Aug 2018 05:22:35 -0700 (PDT) X-Gm-Message-State: APzg51Az4OsJSuM13M+EK49oEF0yiH+BjpkVB+YM/pjOpqXFk8+7HogO WPqEA4Hrk8NKvrC2nZ8rw8alYhjwVOECkART31g= X-Received: by 2002:adf:cc91:: with SMTP id p17-v6mr7456508wrj.226.1535631753843; Thu, 30 Aug 2018 05:22:33 -0700 (PDT) MIME-Version: 1.0 From: Krzysztof Kozlowski Date: Thu, 30 Aug 2018 14:22:22 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Locking for HW crypto accelerators To: Herbert Xu , "David S. Miller" , 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 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? Best regards, Krzysztof