Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp740505ybt; Fri, 26 Jun 2020 10:22:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzclW59L0/vi46vE1FlqB3JnG43Nj4kpFwjG5l4Mvv+sZ1/MHWALD8dBPkRt6iqYwGjaP3m X-Received: by 2002:a17:906:57da:: with SMTP id u26mr3625636ejr.157.1593192120909; Fri, 26 Jun 2020 10:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593192120; cv=none; d=google.com; s=arc-20160816; b=LCaPo8IXDPMDup/sUp3KooIDGktlBb7I8v2b7ocyRPW67x/IqXt5/foVs//cxtF8WC zASVrqjPLTum/cORsZMAHW2ledsRzPxCnK1su3sVtZAWiG5lgQYPTQMuT1H49RcBwKQR w/gAcDaBWX8TSyBZXgV/NfPrPXb8/cUuWtXbtQpd3S48w0C9SjPhSFztbbYYV81w3Zrv oXLSCHSSQGh9pv/ohagGglbDSdtGA3+7RIYMa6l4fhXOUR8arwGAXsNgucE5uNNh/gIw kMeNRMBNw7TUj+TDVUE8YqR9i98coTtQLbuOSr1O68Wa//Lke/SLY8f8nARYj6CRo6T6 ceMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bOGbKuuXHXtIQbM/eAn9KloSV7z60IKyJayl1glo/Zs=; b=we2KitiCXYvvFl5iOSqhXt4jEBT3Th9V+tQuxmdMq7j2PIdVQSA/ZRwdPZ4i0usPf5 MTYvzL/4DJ3YatUXg4pOdLv69WLY82n5XkTVV30TbBaeOOIDa1eKrbowVpbE/dgHyyZX n7yRyxthx3WI4FDS4hDauTkeyACqVho71A4kDaR5WD7u6gwjaesVgFWpZ0e8MCZFT+rR Sk03gJ95/src3AwxksT9n9PGl9EcV2h84SdSuZv8gDokFAmh64RA151gzP/uS7MM4+VW Bpa4lVETdwxCdoc+g74ERd88qajRAw+8ALZ5Nil4rpPl5ZtKX7vQqWZ8Df5tNRkshMtP lL5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1q+wodL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id j13si11674162ejc.314.2020.06.26.10.21.37; Fri, 26 Jun 2020 10:22:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1q+wodL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727843AbgFZQqU (ORCPT + 99 others); Fri, 26 Jun 2020 12:46:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:49534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727779AbgFZQqU (ORCPT ); Fri, 26 Jun 2020 12:46:20 -0400 Received: from gmail.com (unknown [104.132.1.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34A0E20781; Fri, 26 Jun 2020 16:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593189979; bh=/3LoxLF4057wgZmTfhlnbofhYnbOiICrrbf/TSmHFHs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=1q+wodL86TPFmNc+x+aUEA7JqPHajKbmrdBGnBv1znqYozu8EwoloHHYVbVBhZAkg 6gtR3VAbiLsHLeVpqzD1zRYpFefRRqRRS9xyqIeE+8JrAyPAFWBlcaTb9ywdwrlrM0 IVArLToo1Om2esBZa3xjZdY4CK1aUGz9AQPxudXw= Date: Fri, 26 Jun 2020 09:46:17 -0700 From: Eric Biggers To: Mikulas Patocka Cc: Herbert Xu , Mike Snitzer , linux-kernel@vger.kernel.org, dm-devel@redhat.com, linux-crypto@vger.kernel.org, "David S. Miller" , Milan Broz , Jonathan Cameron , George Cherian , Wei Xu , Zaibo Xu Subject: Re: [PATCH 1/3 v2] crypto: introduce the flag CRYPTO_ALG_ALLOCATES_MEMORY Message-ID: <20200626164617.GA211634@gmail.com> References: <20200610121106.GA23137@gondor.apana.org.au> <20200616173620.GA207319@gmail.com> <20200626044534.GA2870@gondor.apana.org.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 26, 2020 at 12:16:33PM -0400, Mikulas Patocka wrote: > +/* > + * Pass these flags down through the crypto API. > + */ > +#define CRYPTO_ALG_INHERITED_FLAGS (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY) This comment is useless. How about: /* * When an algorithm uses another algorithm (e.g., if it's an instance of a * template), these are the flags that always get set on the "outer" algorithm * if any "inner" algorithm has them set. In some cases other flags are * inherited too; these are just the flags that are *always* inherited. */ #define CRYPTO_ALG_INHERITED_FLAGS (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY) Also I wonder about the case where the inner algorithm is a fallback rather than part of a template instance. This patch only handles templates, not fallbacks. Is that intentional? Isn't that technically a bug? > + > +/* > * Transform masks and values (for crt_flags). > */ > #define CRYPTO_TFM_NEED_KEY 0x00000001 > Index: linux-2.6/crypto/authenc.c > =================================================================== > --- linux-2.6.orig/crypto/authenc.c 2020-06-26 17:24:03.566417000 +0200 > +++ linux-2.6/crypto/authenc.c 2020-06-26 17:24:03.566417000 +0200 > @@ -388,7 +388,8 @@ static int crypto_authenc_create(struct > if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) > return -EINVAL; > > - mask = crypto_requires_sync(algt->type, algt->mask); > + mask = crypto_requires_sync(algt->type, algt->mask) | > + crypto_requires_nomem(algt->type, algt->mask); As I suggested earlier, shouldn't there be a function that returns the mask for all inherited flags, rather than handling each flag individually? > > inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); > if (!inst) > @@ -424,7 +425,7 @@ static int crypto_authenc_create(struct > goto err_free_inst; > > inst->alg.base.cra_flags = (auth_base->cra_flags | > - enc->base.cra_flags) & CRYPTO_ALG_ASYNC; > + enc->base.cra_flags) & CRYPTO_ALG_INHERITED_FLAGS; Strange indentation here. Likewise in most of the other files. > Index: linux-2.6/crypto/xts.c > =================================================================== > --- linux-2.6.orig/crypto/xts.c 2020-06-26 17:24:03.566417000 +0200 > +++ linux-2.6/crypto/xts.c 2020-06-26 17:24:03.566417000 +0200 > @@ -415,7 +415,7 @@ static int create(struct crypto_template > } else > goto err_free_inst; > > - inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC; > + inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_INHERITED_FLAGS; > inst->alg.base.cra_priority = alg->base.cra_priority; > inst->alg.base.cra_blocksize = XTS_BLOCK_SIZE; > inst->alg.base.cra_alignmask = alg->base.cra_alignmask | Need to set the mask correctly in this file. > Index: linux-2.6/crypto/adiantum.c > =================================================================== > --- linux-2.6.orig/crypto/adiantum.c 2020-06-26 17:24:03.566417000 +0200 > +++ linux-2.6/crypto/adiantum.c 2020-06-26 17:24:03.566417000 +0200 > @@ -507,7 +507,8 @@ static int adiantum_create(struct crypto > if ((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask) > return -EINVAL; > > - mask = crypto_requires_sync(algt->type, algt->mask); > + mask = crypto_requires_sync(algt->type, algt->mask) | > + crypto_requires_nomem(algt->type, algt->mask); > > inst = kzalloc(sizeof(*inst) + sizeof(*ictx), GFP_KERNEL); > if (!inst) Need to use CRYPTO_ALG_INHERITED_FLAGS in this file. - Eric