Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp447488pxb; Wed, 3 Mar 2021 07:14:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8f52V23c3FzDqp4YDtRq42x7t950nrk5+k+iaTlMFt08+WbkPfvfyBlpQ/ERdgOMxuvEb X-Received: by 2002:a17:906:4e57:: with SMTP id g23mr25854403ejw.47.1614784457330; Wed, 03 Mar 2021 07:14:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614784457; cv=none; d=google.com; s=arc-20160816; b=iiYL5wjNKPpaFA1fFZTYdXXZUfjk30No6jDiluCCWGV9e3lpeZ8kUWCZEDFRgOrWJy Hv4frvLmkPdn45CNlFdpZySlGmQg4Bf/NIc7xXhkgUHZNse5r4C7M2eSkO6jwihHpZSI R2Hmc+niBUTGOj+JkUHA7Q6sU04RL1HYC7pF7EZvxpOrZmI+CeAWmvtMOP/ZKOSYhzj3 OSgQ1gYpENA7RlCOykeko0Nbv3eK8IVBbkqG0d84rlue0LRX5D8ZQxGgcuPMl/T7yP6f 1UgIafi0MuKfLh7jrOQhHuWz4WoWdme7lbPg8062jqgHxAdg39457PbiF7yOhX0wzXOd c8+w== 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=Ef9JXphWgqFTlNnSFPVXwkHbmzNjVJ1TQ1GnqHo4+ak=; b=YicCHVPkloTy3+pHswBQJYzAs5590QC/EN2Ax7QgnX9N0S2p0SBDOgRtlp47h31wSr F72T0H2g7a064FC+zwAI3E3v2q9B/8WwFSwIOKSBDx7zjdJUiVHNeRTHgzgENSZvhqV9 AxCySFShiqLUsgxqsTnZcSn2y4CUTu0pE/2XRzdlNyE4wHJOoo6Q0ky/gYl0dOTkfQYx NPi1BZzYe2wZ+RNiwBJP9mGCbEmlECjVIK1jj566Abg4li8/xMDeNkUNV8QS87XlbDfm bL7OlUrOeyNUawhtm3ur7s3iIVdIqDItt8TgIZflxfrzrqQiUlPHMRBXW8wCWZYNwLUK JOVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gZkYz0sb; 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 jg13si16161524ejc.126.2021.03.03.07.13.48; Wed, 03 Mar 2021 07:14:17 -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=gZkYz0sb; 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 S1343720AbhCAWhd (ORCPT + 99 others); Mon, 1 Mar 2021 17:37:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:35580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238928AbhCARn4 (ORCPT ); Mon, 1 Mar 2021 12:43:56 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 56ABB64FD2; Mon, 1 Mar 2021 16:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617896; bh=jCzAlN5HYHnOMu49/eD3f2VGWjCNuMUEg0S3O5d7qZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gZkYz0sbfyjx4vmFvYhy96GatZx+w/l3ZxP04EXpcjnIQAUCNQoFEOy6WbDHY/QkU PWWghYOZp/Hwsy54RR0CDuDoi2D6E69DUWF5JzKjnvmGPgbiVv32u8tHpQyiuGV8oC mwgtkaTGt22ha19bGrNel9Q6qZkeNGcS4QbgvCwY= 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 5.4 235/340] blk-settings: align max_sectors on "logical_block_size" boundary Date: Mon, 1 Mar 2021 17:12:59 +0100 Message-Id: <20210301161059.858406362@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161048.294656001@linuxfoundation.org> References: <20210301161048.294656001@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 @@ -473,6 +473,14 @@ void blk_queue_stack_limits(struct reque } EXPORT_SYMBOL(blk_queue_stack_limits); +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_stack_limits - adjust queue_limits for stacked devices * @t: the stacking driver limits (top device) @@ -586,6 +594,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);