Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp52456ybc; Fri, 22 Nov 2019 01:55:27 -0800 (PST) X-Google-Smtp-Source: APXvYqz/1+fLeq5o9aeeqWZ2hNoa2ibuhXIl7ZG5AuDmVNna1o5h4I95OaQouCH32ZA7D14XWUmN X-Received: by 2002:a05:6402:21c5:: with SMTP id bi5mr17716edb.7.1574416527875; Fri, 22 Nov 2019 01:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574416527; cv=none; d=google.com; s=arc-20160816; b=XlNmq9OruBbKY560CK33/MACHgSciXE27smZDYryxUbL1PzaxthSeS8FREIoyZ8ewU OQEaaw5R2UNLygdt1yb7drnKS5aFbFh19EGrCpXN43Osm0T1088dxp/aEZ+fa/2ikYd+ vDT4z2qo5V6LoCO177EBsJJCa0dBIXej08QDs0tNUxJ1HwGYH1eOEbx5PZXr0sbevDFV IRob1CpbGpDP5Rl+SybKEY8/fFJNPvPgQO5o5FoJbCEejKenG3+VnSY6thOp+Yg2ViXM Z7RSosOKdyOuMKp5BVn8JDHK5nRsDtqOH4fVkMsd3ulPTSwCR5ZeF8lnO9rkygzUHeyZ EdrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject; bh=lCttg7gjuQc9SN0lgmKbBJMDSDsRvkHZUedoflc9b7g=; b=tbH0N3ZHCgTB5g9ds+EV2CxOzkPizfzReJ9NjIEcWBDHRdAxp4VFFDpSwGIIq8t8pb Hu5BJ1x5ezJVNFxhd/VHU/Tc2lOg5M3mzUg7B3/EN1K2qKhtAyGi0Zu9pDz2jSXQPXTn 87qiI7tuLWMLZa9oxSji6iLqKNy8jmTp+btO7b0TpXde1bX2kyD2VnC3BVV3K4t65D3C NJQYdDGq589lacGBYv+VSz+LCFxqB9vxmR1grxYnKifkxXRWGmK2e8PqowFEr+w8LhiR DZAft2x52/JyHdnIgHvwB4SfgX6AJMQXCNCvsNzOYi7+GcXIx4HR7Cw5yZ07rQF4PMr9 r5+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q27si4104492ejr.143.2019.11.22.01.55.02; Fri, 22 Nov 2019 01:55:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726526AbfKVJy4 (ORCPT + 99 others); Fri, 22 Nov 2019 04:54:56 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55858 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726100AbfKVJy4 (ORCPT ); Fri, 22 Nov 2019 04:54:56 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xAM9qd95081325 for ; Fri, 22 Nov 2019 04:54:55 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2wdu63bd3p-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 22 Nov 2019 04:54:55 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 22 Nov 2019 09:54:52 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 22 Nov 2019 09:54:51 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xAM9sCSQ29688316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 22 Nov 2019 09:54:12 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5123A42052; Fri, 22 Nov 2019 09:54:50 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD75B42047; Fri, 22 Nov 2019 09:54:49 +0000 (GMT) Received: from funtu.home (unknown [9.145.67.101]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 22 Nov 2019 09:54:49 +0000 (GMT) Subject: Re: [PATCH 2/3] s390/crypto: Rework on paes implementation To: Herbert Xu Cc: linux-crypto@vger.kernel.org, ebiggers@kernel.org, heiko.carstens@de.ibm.com, gor@linux.ibm.com References: <20191113105523.8007-1-freude@linux.ibm.com> <20191113105523.8007-3-freude@linux.ibm.com> <20191122081338.6bdjevtyttpdzzwl@gondor.apana.org.au> From: Harald Freudenberger Date: Fri, 22 Nov 2019 10:54:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191122081338.6bdjevtyttpdzzwl@gondor.apana.org.au> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 19112209-4275-0000-0000-00000384CDB6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19112209-4276-0000-0000-000038984DD1 Message-Id: <87e9dbee-4024-602c-7717-051df3ac644d@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-22_01:2019-11-21,2019-11-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 clxscore=1015 bulkscore=0 impostorscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-1911220087 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 22.11.19 09:13, Herbert Xu wrote: > On Wed, Nov 13, 2019 at 11:55:22AM +0100, Harald Freudenberger wrote: >> @@ -129,6 +128,7 @@ static int ecb_paes_init(struct crypto_skcipher *tfm) >> struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm); >> >> ctx->kb.key = NULL; >> + spin_lock_init(&ctx->pk_lock); > This makes no sense. The context is per-tfm, and each tfm should > have a single key at any time. The synchronisation of setkey vs. > crypto operations is left to the user of the tfm, not the > implementor. > > So why do you need this spin lock at all? > > Cheers, The setkey() sets the base key material (usually a secure key) to an tfm instance. From this key a 'protected key' (pkey) is derived which may get invalid at any time and may need to get re-derived from the base key material. An tfm instance may be shared, so the context where the pkey is stored into is also shared. So when a pkey gets invalid there is a need to update the pkey value within the context struct. This update needs to be done atomic as another thread may concurrently use this pkey value. That's all what this spinlock does. Make sure read and write operations on the pkey within the context are atomic. It is still possible that two threads copy the pkey, try to use it, find out that it is invalid and needs refresh, re-derive and both update the pkey memory serialized by the spinlock. But this is no issue. The spinlock makes sure the stored pkey is always a consistent pkey (which may be valid or invalid but not corrupted). Hope this makes it clear Thanks