Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2682019ybb; Fri, 27 Mar 2020 10:06:15 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs9g0IMPwswbZ07qcMkI2N+Z1r8r24Rv+ZBAxAKgwlPtdkVvHYB5KQeHnnwzEosiAtFH6N2 X-Received: by 2002:aca:db56:: with SMTP id s83mr4800419oig.171.1585328775592; Fri, 27 Mar 2020 10:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585328775; cv=none; d=google.com; s=arc-20160816; b=wyWSl+vr6RpNx0y2Z/UnGbVL5zE7NulJZLvmHS/+L99WYiPilJlWNllIAtPlA7sqeM NX8g32QwkjI09936Vfub3tC+WTKGIwvNqPk1gv4iC2i0dffmdrt7EAlRtbmSxaMZI1i+ rXHcgrwsacuuqAC1SmzTs+iHCEBufBrNBmLRMgbTH7IXfmqcBxvoFr/bM5cnkcxnHGbf ubsymAZPYN6WJiiJ8H/s0DSRjdNx54xX/et+pWj5nL7elSucL2iKeBeEH5GEEIMDREBE Gj80Vk90YpYU0pXj4bVyM7g2HCV29AtGuItt2/kwW1d8uaDl+5X96kfPBaKfIMUtTjD0 8org== 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=nQwtzNXpf86itTjaB1edkzN5h3XvovjaCziQk9DtCjM=; b=GYAq4sHrP4LTnKAMit9gr+3nAAsSVFZRIodUP705KdPCkP9iSzxb/lTwxd3JweaYYW 21Wb+Su7NFi9xCkg1MuQYRzxrlTOB8h6W8HbgZz2DetGPe1PRuNZowImXAUcJZCKOMTs IwzIHJvwSb5xI1t0XZlffiCfAx4VHP48naLlS0xHWcNgtnuy/apxZjaYGw8ItkfKjbrk POxtVeaCG4PVDN+VHKkiARHZEb0LXQMQBDSJ0vCKiMNk++s39DyFKisVlOUY4bXUwq/D O5A5uhZAj+m7H0TkAyWBBR1jlWV9cXZb2Yp4h++XZxkHVHEPOykRwjVzSt7THROC9QkX HlEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tJHUKbZB; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 g1si1073818otn.200.2020.03.27.10.06.03; Fri, 27 Mar 2020 10:06:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tJHUKbZB; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbgC0RFg (ORCPT + 99 others); Fri, 27 Mar 2020 13:05:36 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:44206 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727254AbgC0RFf (ORCPT ); Fri, 27 Mar 2020 13:05:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nQwtzNXpf86itTjaB1edkzN5h3XvovjaCziQk9DtCjM=; b=tJHUKbZBjsey04PmV3H0dCje7e bYKkkq6017QpkZgT1ElJKViJOrTCd7UCVOEZRVRF6tPwwlnll/gKoVxqCy/1XMb/AHQaUrLBj/NC3 tBw4POPUFD3N/CFouNP73J5J5wYWrOGmz+YqLJ3hKO5+/AhYSOTmdJvvjogLQxzbSLqpgAoASBzgI QqiQJeYh+w/7R4WbwSgVu5ZYKTZyajcVh058adQbz/pv1GRD16BS0VUde8wkrh3+gCs0MZljoIzIM GJQRxIF3ZihKK2bgZ2ln/osQrAbO/suKfl6oWss51RtXITpHhUsGodIPRNRreKE0Y8uC8VX9l0j3a LhqGwHBg==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jHsQI-0002G0-5a; Fri, 27 Mar 2020 17:05:34 +0000 Date: Fri, 27 Mar 2020 10:05:34 -0700 From: Christoph Hellwig To: Eric Biggers Cc: Satya Tangirala , linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-ext4@vger.kernel.org, Barani Muthukumaran , Kuohong Wang , Kim Boojin Subject: Re: [PATCH v9 02/11] block: Inline encryption support for blk-mq Message-ID: <20200327170534.GB24682@infradead.org> References: <20200326030702.223233-1-satyat@google.com> <20200326030702.223233-3-satyat@google.com> <20200326200511.GA186343@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200326200511.GA186343@gmail.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Mar 26, 2020 at 01:05:11PM -0700, Eric Biggers wrote: > > +{ > > + int i = 0; > > + unsigned int inc = bytes >> bc->bc_key->data_unit_size_bits; > > + > > + while (i < BLK_CRYPTO_DUN_ARRAY_SIZE) { > > + if (bc->bc_dun[i] + inc != next_dun[i]) > > + return false; > > + /* > > + * If addition of inc to the current entry caused an overflow, > > + * then we have to carry "1" for the next entry - so inc > > + * needs to be "1" for the next loop iteration). Otherwise, > > + * we need inc to be 0 for the next loop iteration. Since > > + * overflow can be determined by (bc->bc_dun[i] + inc) < inc > > + * we can do the following. > > + */ > > + inc = ((bc->bc_dun[i] + inc) < inc); > > + i++; > > + } > > This comment is verbose but doesn't really explain what's going on. > I think it would be much more useful to add comments like: Also the code is still weird. Odd double whitespaces, expression that evaluate to bool. > > /* > * If the addition in this limb overflowed, then the carry bit > * into the next limb is 1. Else the carry bit is 0. > */ > inc = ((bc->bc_dun[i] + inc) < inc); if (bc->bc_dun[i] + carry < carry) carry = 1; else carry = 0; > > > +blk_status_t __blk_crypto_init_request(struct request *rq, > > + const struct blk_crypto_key *key) > > +{ > > + return blk_ksm_get_slot_for_key(rq->q->ksm, key, &rq->crypt_keyslot); > > +} > > The comment of this function seems outdated. All it does it get a keyslot, but > the comment talks about initializing "crypto fields" (plural). This is a classic case where I think the top of the function comment is entirely useless. If there is a single caller in core code and the function is completely trivial, there really is no point in a multi-line comment. Comment should explain something unexpected or non-trivial, while much of the comments in this series are just boilerplate making the code harder to read. > > blk_queue_bounce(q, &bio); > > __blk_queue_split(q, &bio, &nr_segs); > > @@ -2002,6 +2006,14 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) > > > > cookie = request_to_qc_t(data.hctx, rq); > > > > + ret = blk_crypto_init_request(rq, bio_crypt_key(bio)); > > + if (ret != BLK_STS_OK) { > > + bio->bi_status = ret; > > + bio_endio(bio); > > + blk_mq_free_request(rq); > > + return BLK_QC_T_NONE; > > + } > > + > > blk_mq_bio_to_request(rq, bio, nr_segs); > > Wouldn't it make a lot more sense to do blk_crypto_init_request() after > blk_mq_bio_to_request() rather than before? > > I.e., initialize request::crypt_ctx first, *then* get the keyslot. Not the > other way around. > > That would allow removing the second argument to blk_crypto_init_request() and > removing bio_crypt_key(). blk_crypto_init_request() would only need to take in > the struct request. And we can fail just the request on an error, so yes this doesn't seem too bad.