Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1053020pxb; Thu, 15 Apr 2021 12:46:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwryIvlaEHzWVlSPy6QSEHuq5qmxvX+YApN4gNTTt8pKm2YuDM+uqCwn7tOdNPJI+7o/RGh X-Received: by 2002:a17:906:cc9b:: with SMTP id oq27mr5083785ejb.81.1618515973588; Thu, 15 Apr 2021 12:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618515973; cv=none; d=google.com; s=arc-20160816; b=BNIJTGVTFdyhrzoag1D9bl7SPpSI2sZqdRObseW25ICpfpVER+hQjBrh5IRj91UBKA Tzi+yGWzT6lpK7ufqQsU1BSGtMcmCpjHe7t9ntZvuiZ2x8pQ0ZMcMf11AeE0sDW3pD+u YU+IJ64lZYbI8/l6cYe49YLkplg88CA18Yn6PNcALJoF+cZiuyxmjDwb7tKJJS/ykINW TcKKz2UytGBnTFYYGoP9eBskcYx37cbJsG/JMs+PnZYcpndkFS5dGLK/Y9K6jU+2FkzF 8KFxaMdiXSGTeV/8NTndZTm9hiZDgMuHnOBZsoyn3MtOLziWV5IrqCxLP9tKo7HQy8u+ 5NZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=r6OTG8tCjSm+ISSzziasSHnZnewxNFtz9a0lsk7NdKw=; b=ISRMpNyDcH6TiqDxifAD8uolnSaiUTNM1lpMHcIXgMDEzy6AzlFWaBLhxsGz60+h+7 q4dgCh9POZYz4rZQEoc70wcgS9VDCT0ZKWthJc/12QrAls+gSQXCW9tqSjH5/h+d52nD a7Xr5+ufFnRDBq79oB73P1FR9rFXfwgv6qkWquepKrKAbhORmujmHQ0jupnXl73yvv1I 2I1N1Dbg3KdtyOtyhFGQ9go7Ya46Ngpjhp3V3NEquFAcO0mVv7uD3eypl7j+Ct+Cg6YR /fZtJSESIdoa5LGSKEC0JRrmgROGlfRShS5NT6+iIUq/wDloxuhCdmHKeHU+j3fy+l6y pHIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NopJ6oGL; 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 k9si3500330eje.640.2021.04.15.12.45.49; Thu, 15 Apr 2021 12:46:13 -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=k20201202 header.b=NopJ6oGL; 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 S234735AbhDOTo4 (ORCPT + 99 others); Thu, 15 Apr 2021 15:44:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:56238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234226AbhDOToz (ORCPT ); Thu, 15 Apr 2021 15:44:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9F0CA6115B; Thu, 15 Apr 2021 19:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618515871; bh=oU1cQr3wkqayozcT7QZOVj1UOm40p9k1jAVx6Ebpk7w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NopJ6oGLjiZbNcp/BrmHyV+vsHX0w0jTtQvJJUDYAPpkpmV7L9CtsponNSRmdJ1nC LAq04IjmE6ilLWBWAF99hPFP96sEZRM/6GgA10boU+DQR9rLbvzh6dbt8ijVsXRDjC C58C6fR6NUlb05f7LfyWXMFg/mlHN+lg4k8OGeSY8Bd69bhVcEvHnO2hySM3iwfa1+ pN3/w3paQ20SOzGYZKkRz1sNyGc5QOpmvmpDZCUAGwXFc57Af1ybduNiLiDiete/9B 5KxURBYY6Rzl+ypVZRkqrnqpKtM2vT1dDUPH35s4bOo+PHB8+bkddbBdgUrEjRNR/U tEGuDPeM4pZ9w== Date: Thu, 15 Apr 2021 12:44:30 -0700 From: Eric Biggers To: Satya Tangirala Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Jens Axboe Subject: Re: [PATCH v2 4/8] block: introduce bio_required_sector_alignment() Message-ID: References: <20210325212609.492188-1-satyat@google.com> <20210325212609.492188-5-satyat@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210325212609.492188-5-satyat@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 25, 2021 at 09:26:05PM +0000, Satya Tangirala wrote: > This function returns the required alignment for the number of sectors in > a bio. In particular, the number of sectors passed to bio_split() must be > aligned to this value. > > Signed-off-by: Satya Tangirala > --- > block/blk.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/block/blk.h b/block/blk.h > index 3b53e44b967e..5ef207a6d34c 100644 > --- a/block/blk.h > +++ b/block/blk.h > @@ -261,6 +261,18 @@ static inline unsigned int bio_allowed_max_sectors(struct request_queue *q) > return round_down(UINT_MAX, queue_logical_block_size(q)) >> 9; > } > > +/* > + * The required sector alignment for a bio. The number of sectors in any bio > + * that's constructed/split must be aligned to this value. What does "constructed" mean in this context? > + */ > +static inline unsigned int bio_required_sector_alignment(struct bio *bio) > +{ > + struct request_queue *q = bio->bi_bdev->bd_disk->queue; > + > + return max(queue_logical_block_size(q) >> SECTOR_SHIFT, > + blk_crypto_bio_sectors_alignment(bio)); > +} It would be slightly simpler to use bdev_logical_block_size(bio->bi_bdev) instead of queue_logical_block_size(bio->bi_bdev->bd_disk->queue). Also, if there's interest in avoiding the branch implied by the max() here, it would be possible to take advantage of the values being powers of 2 as follows: static inline unsigned int bio_required_sector_alignment(struct bio *bio) { unsigned int alignmask = (bdev_logical_block_size(q) >> SECTOR_SHIFT) - 1; alignmask |= blk_crypto_bio_sectors_alignment(bio) - 1; return alignmask + 1; }