Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp411155pxb; Wed, 3 Mar 2021 06:28:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxervFBIy36zVg4tARMnaw5tmJNFGlFx3EpsNHEuBZNEj6eY9De9f4/IKa+iscxxZRfiv2D X-Received: by 2002:aa7:c0c7:: with SMTP id j7mr13005387edp.298.1614781736209; Wed, 03 Mar 2021 06:28:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614781736; cv=none; d=google.com; s=arc-20160816; b=s4pe32H98dk1UXus7/eGWjWR1AgQz/hx5Sv7YQnx8Zfgm2VyCXAkdgRooiUMwdSpvw sI6Xvn7/VY4ShTfR+iRdaSAR8q77hwyDdiy19+6ueyiydBhJ6IG7N2e0Edw9slX2EU39 qQDdD7Gxr0jFcsoFNr+ercraxkRgPflWvKLAx7MWcRl9POi5+1E2rBvPt1LPhMGTwCUB Qs5CPVbynuijvH4MUvC3MHi36ERZ+FPZepS2XbH2gwKVTZed0tvgxDP9UH2ZgQpEvcR0 n/4LA3qIoCvFpgXyIuMk+eFFSZA7gNeV9UqxnC/wBaetf1FydKJWA3jZGWKPv0niUNIe 1Uow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dIFxmO1FxVBboG5CD/knFFwDs07VPPqtB1yGRLEfleo=; b=E1fFb1uhJS/AROMvIUkUiIDZQOZv1nRKTvjUa1x7Whb+wtfndOVLG1VCOEXfuoaBi/ ziwizTLk4u9J+dO80YXLURJv92Z5Idk+y6BaFvRNtP3e8NVcD156IQ1DnLB/Ofsczx8I LevJN+6a7HSXP8q5JuHp3izaGkSyY1mvaljZOL0lBAKbSQCIfb1L4nbUgUn6lyYxyyTE FKxMeL5lbA0ziONV1j1+mKETxxo2S5X2Qs5j8Nnjo4RQt4DySHWeoUej82IewDV29+kL HT2qAu4Jb9VALM8A5Xr1OifG8B+eIjGWkBlFzRi0Il+B2bCt1WBmuq6vDYnL8YIjO5LH kfOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zJ5N+LUa; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m22si4121276ejr.463.2021.03.03.06.28.28; Wed, 03 Mar 2021 06:28:56 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=zJ5N+LUa; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239841AbhCAVLD (ORCPT + 99 others); Mon, 1 Mar 2021 16:11:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:52648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237852AbhCARNg (ORCPT ); Mon, 1 Mar 2021 12:13:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E26464E42; Mon, 1 Mar 2021 16:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617031; bh=RsbPo0XyIseqr+G8QIRElmcAco+518rnGF0zBeON3Zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zJ5N+LUaxHUbF11jzIpGGv3PMbvWg+v3ex/54/uNbzFNIsNkBEGHaMffJnA8Zd2gO ahqxetHDFED/n0dhvdUv8152c+mHXusta4PN/mUg7+O8/eB5crq1csQOIwfHA6tL96 3PcJDdWhKYmhmEZGUWMV/7EArRZbWol7wUhob9l8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ming Lei , Mikulas Patocka , Jens Axboe Subject: [PATCH 4.19 178/247] blk-settings: align max_sectors on "logical_block_size" boundary Date: Mon, 1 Mar 2021 17:13:18 +0100 Message-Id: <20210301161040.366245892@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit 97f433c3601a24d3513d06f575a389a2ca4e11e4 upstream. We get I/O errors when we run md-raid1 on the top of dm-integrity on the top of ramdisk. device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1 device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1 device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb The ramdisk device has logical_block_size 512 and max_sectors 255. The dm-integrity device uses logical_block_size 4096 and it doesn't affect the "max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have a device with max_sectors not aligned on logical_block_size. The md-raid device sees that the underlying leg has max_sectors 255 and it will split the bios on 255-sector boundary, making the bios unaligned on logical_block_size. In order to fix the bug, we round down max_sectors to logical_block_size. Cc: stable@vger.kernel.org Reviewed-by: Ming Lei Signed-off-by: Mikulas Patocka Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-settings.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -513,6 +513,14 @@ void blk_queue_io_opt(struct request_que } EXPORT_SYMBOL(blk_queue_io_opt); +static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs) +{ + sectors = round_down(sectors, lbs >> SECTOR_SHIFT); + if (sectors < PAGE_SIZE >> SECTOR_SHIFT) + sectors = PAGE_SIZE >> SECTOR_SHIFT; + return sectors; +} + /** * blk_queue_stack_limits - inherit underlying queue limits for stacked drivers * @t: the stacking driver (top) @@ -639,6 +647,10 @@ int blk_stack_limits(struct queue_limits ret = -1; } + t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size); + t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size); + t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size); + /* Discard alignment and granularity */ if (b->discard_granularity) { alignment = queue_limit_discard_alignment(b, start);