Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp618546ybh; Tue, 21 Jul 2020 03:54:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaTitPr0BTm42hjTy+Wk1uIvpDaQ6ciT8cZlCtmTvnN6ktM7DJen+A9ulcr/3SKmWh4//7 X-Received: by 2002:a17:907:2108:: with SMTP id qn8mr24429624ejb.16.1595328877505; Tue, 21 Jul 2020 03:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595328877; cv=none; d=google.com; s=arc-20160816; b=iwQjpNM+FgqirgzE+BBm1zN1eOul8JOrH1CZiSdCD9/J9wlt9wMRpbVmr7G/qKl83z XH0pMr/sXxExsLw0gLet4H6jE4PZOVCLfiwTV2UQcwkIxHq4RY6HjJhYWtfbdtzMogpn iw8T7QMZJs3mSpCIDdL+b/WcaDHJWQEmxcGnemPCFr+QDYtcS26GYzQx/BRgFQ0V3/g7 ow+y23buGVpgdPUCjZ7a+dTDbRXfEPwLbRYJgl+BdfXxSpj8oi/pu2j3BMrKis0oX2eL rKJtMQ10SOQQsr81ANnSVgI9Aq/RmTPNC28ClKrOoUuL+BT1Vs7hvKV81LMxc2vxEga1 ulGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mU9LuvbxIIqQES8VkndiAmGnMN0LZw77R+JT+vMfjKM=; b=VePHvD3VtKwjIRMjEATria98Ms0b34LmklDagsLSCxDrxA/giMwTw1tpLEoyG8Adiz QzXUo6Rwi5UPIfv1lOKeEfHvO5mNKTrMvXNp8emK8vUAgmUfBPjWf15azuPGjQmrG2tO dAeQKULq0WsbUKHy6RjLqZRNK8BE3bw/vL91s4wyLNFRL8pY8OyFqFY3WOdIQHLS5IDk w3RwxK4uIBpPC5Td1GHrjtZHNEp8GEcPvHC/MYtuhk3YUS9vD/NjcZp+9aVDtXJqZh5A 0VO3fb7FInFgBP0QyhkK54Rtv1SWpKmkduMjSXC4TaydaV3813j2GpYy0/QbN5u6uVrO /Lpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RPpe2T/p"; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si12283252edv.457.2020.07.21.03.54.14; Tue, 21 Jul 2020 03:54:37 -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=@redhat.com header.s=mimecast20190719 header.b="RPpe2T/p"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729390AbgGUKxf (ORCPT + 99 others); Tue, 21 Jul 2020 06:53:35 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:46634 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729378AbgGUKxe (ORCPT ); Tue, 21 Jul 2020 06:53:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595328813; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mU9LuvbxIIqQES8VkndiAmGnMN0LZw77R+JT+vMfjKM=; b=RPpe2T/pkgdhmritA4f1a/I1OW9Ye6X1ygMWLUCvvFsXu8lqXkuUNvPx9WYxsuMDJ/RUH2 hfqdry5zXrE1PXaM7HIkkjxwg4bXmqnYov/AkiE/N/5fmaV1a8BdLXTBDp9NOvo1clzOrv NU98InWy5vxuU2gPCFp2JMoSsaF5t+Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-TU50TFU3PYG9zwlYETAStw-1; Tue, 21 Jul 2020 06:53:29 -0400 X-MC-Unique: TU50TFU3PYG9zwlYETAStw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 693008014D7; Tue, 21 Jul 2020 10:53:26 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87CB47621A; Tue, 21 Jul 2020 10:53:09 +0000 (UTC) From: Maxim Levitsky To: linux-kernel@vger.kernel.org Cc: Keith Busch , Josef Bacik , linux-block@vger.kernel.org (open list:BLOCK LAYER), Sagi Grimberg , Jens Axboe , linux-nvme@lists.infradead.org (open list:NVM EXPRESS DRIVER), linux-scsi@vger.kernel.org (open list:SCSI CDROM DRIVER), Tejun Heo , Bart Van Assche , "Martin K. Petersen" , Damien Le Moal , Jason Wang , Maxim Levitsky , Stefan Hajnoczi , Colin Ian King , "Michael S. Tsirkin" , Paolo Bonzini , Ulf Hansson , Ajay Joshi , Ming Lei , linux-mmc@vger.kernel.org (open list:SONY MEMORYSTICK SUBSYSTEM), Christoph Hellwig , Satya Tangirala , nbd@other.debian.org (open list:NETWORK BLOCK DEVICE (NBD)), Hou Tao , Jens Axboe , virtualization@lists.linux-foundation.org (open list:VIRTIO CORE AND NET DRIVERS), "James E.J. Bottomley" , Alex Dubov , Maxim Levitsky Subject: [PATCH 01/10] block: introduce blk_is_valid_logical_block_size Date: Tue, 21 Jul 2020 13:52:30 +0300 Message-Id: <20200721105239.8270-2-mlevitsk@redhat.com> In-Reply-To: <20200721105239.8270-1-mlevitsk@redhat.com> References: <20200721105239.8270-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kernel block layer has never supported logical block sizes less that SECTOR_SIZE nor larger that PAGE_SIZE. Some drivers have runtime configurable block size, so it makes sense to have common helper for that. Signed-off-by: Maxim Levitsky --- block/blk-settings.c | 18 ++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 19 insertions(+) diff --git a/block/blk-settings.c b/block/blk-settings.c index 9a2c23cd97007..3c4ef0d00c2bc 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -311,6 +311,21 @@ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size) } EXPORT_SYMBOL(blk_queue_max_segment_size); + +/** + * blk_check_logical_block_size - check if logical block size is supported + * by the kernel + * @size: the logical block size, in bytes + * + * Description: + * This function checks if the block layers supports given block size + **/ +bool blk_is_valid_logical_block_size(unsigned int size) +{ + return size >= SECTOR_SIZE && size <= PAGE_SIZE && !is_power_of_2(size); +} +EXPORT_SYMBOL(blk_is_valid_logical_block_size); + /** * blk_queue_logical_block_size - set logical block size for the queue * @q: the request queue for the device @@ -323,6 +338,8 @@ EXPORT_SYMBOL(blk_queue_max_segment_size); **/ void blk_queue_logical_block_size(struct request_queue *q, unsigned int size) { + WARN_ON(!blk_is_valid_logical_block_size(size)); + q->limits.logical_block_size = size; if (q->limits.physical_block_size < size) @@ -330,6 +347,7 @@ void blk_queue_logical_block_size(struct request_queue *q, unsigned int size) if (q->limits.io_min < q->limits.physical_block_size) q->limits.io_min = q->limits.physical_block_size; + } EXPORT_SYMBOL(blk_queue_logical_block_size); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 57241417ff2f8..2ed3151397e41 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1099,6 +1099,7 @@ extern void blk_queue_max_write_same_sectors(struct request_queue *q, unsigned int max_write_same_sectors); extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, unsigned int max_write_same_sectors); +extern bool blk_is_valid_logical_block_size(unsigned int size); extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); extern void blk_queue_max_zone_append_sectors(struct request_queue *q, unsigned int max_zone_append_sectors); -- 2.26.2