Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3493881imu; Sun, 11 Nov 2018 16:21:44 -0800 (PST) X-Google-Smtp-Source: AJdET5eWqrU3twqKUCNWESqeY9jRLKrNth4pdKZpBvTeh6DF+XzqKONd47lT0q7/IUwqYR7Sl3kv X-Received: by 2002:a63:6dc8:: with SMTP id i191mr15193964pgc.215.1541982104229; Sun, 11 Nov 2018 16:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541982104; cv=none; d=google.com; s=arc-20160816; b=wryqyTwzKv6Gu4JPOm5AHU+R3rkGN9si3+ydzhZPR1LF9tVIl2vEleRVpegXUnUOPJ nUDAKoIxNorhaVn3310PkmsBSW9LlTE5cH80NMA89DMmllChFK5KycjucocvJUhbHUbr aljUdHGuuilcWLA4GLx528aymwVNAT9Tv4Xijoz/O+mWFkSw0kz50TR40P2D2Bnpvxe/ U54TSxTavCm8fQEW1FS7gKp7ZrkcvTLZuhf6rdCuCuYV37KS5h5jVVZEKA//2/vnlPWw YKhL/lGm7DZwSV4qlNVELPcYheiI0W3mn+7Zu8Tcm1a3Q8jsGTWhUMSZE3Be+NjNW/BV xLBA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uvrhQgIof6H/4u9GR5iTydCv222bWqW1ueGYA/xZaJo=; b=zz5JGIZwEVWjWBmxB/iu3RVzRwrZLIznP8EDxi8tWy5FF+J+P+WaQZAvwrpN6YzsZC JxvPU25jrUUBy33cyeXq6Gxvm+D0VV8DH5PDR6lKnjGzQ0R+7BtcZ9MPAJ+f9jvqDWYu cJNVU6ExfGjIZIxP0ZRNrGYCdBaWZ21e24hGe8fQitkBmQ6pQCxeNhxTBAJowI4mU0gx 54XyASuwJtjQV5uTf/scNzEcNtba078n0b8XACbdv+EeD4JkOgYch3QoVazcpUab9L2o IDl98v4E0PSJ4zrvQkULf8Tw96fLIpgkGgWK/lKYfIw0GIrtzIBkjEaocq/q/H1QYyCF S17Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V/WHzhhm"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 h3si15152663pgi.391.2018.11.11.16.21.29; Sun, 11 Nov 2018 16:21:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V/WHzhhm"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730087AbeKLKKY (ORCPT + 99 others); Mon, 12 Nov 2018 05:10:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:58446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729838AbeKLIQy (ORCPT ); Mon, 12 Nov 2018 03:16:54 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8351021731; Sun, 11 Nov 2018 22:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975218; bh=lXmGe3Ww/Be1jzRCxsv4hwAicQxyDG883iVOw8d4Jjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/WHzhhmagiM9zc+gvbWj6KCwAIQQTZUVF3xq4m3g94o8ktB2AvafIQLITRoK/y2N SpoQDQyolhukQARZ0gz1SC6Bt/o5+db2PDhLlAUhFuMTEOFG8270BOIlyUo/nM85CD iyGlaVPxPsJqK3GuX/UU3Kfeul/mTLeDxakokSFU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Snitzer , Christoph Hellwig , Xiao Ni , Mariusz Dabrowski , Rui Salvaterra , Ming Lei , Jens Axboe Subject: [PATCH 4.19 019/361] block: make sure discard bio is aligned with logical block size Date: Sun, 11 Nov 2018 14:16:06 -0800 Message-Id: <20181111221622.414059882@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ming Lei commit 1adfc5e4136f5967d591c399aff95b3b035f16b7 upstream. Obviously the created discard bio has to be aligned with logical block size. This patch introduces the helper of bio_allowed_max_sectors() for this purpose. Cc: stable@vger.kernel.org Cc: Mike Snitzer Cc: Christoph Hellwig Cc: Xiao Ni Cc: Mariusz Dabrowski Fixes: 744889b7cbb56a6 ("block: don't deal with discard limit in blkdev_issue_discard()") Fixes: a22c4d7e34402cc ("block: re-add discard_granularity and alignment checks") Reported-by: Rui Salvaterra Tested-by: Rui Salvaterra Signed-off-by: Ming Lei Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-lib.c | 3 +-- block/blk-merge.c | 3 ++- block/blk.h | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -58,8 +58,7 @@ int __blkdev_issue_discard(struct block_ if (!req_sects) goto fail; - if (req_sects > UINT_MAX >> 9) - req_sects = UINT_MAX >> 9; + req_sects = min(req_sects, bio_allowed_max_sectors(q)); end_sect = sector + req_sects; --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -27,7 +27,8 @@ static struct bio *blk_bio_discard_split /* Zero-sector (unknown) and one-sector granularities are the same. */ granularity = max(q->limits.discard_granularity >> 9, 1U); - max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9); + max_discard_sectors = min(q->limits.max_discard_sectors, + bio_allowed_max_sectors(q)); max_discard_sectors -= max_discard_sectors % granularity; if (unlikely(!max_discard_sectors)) { --- a/block/blk.h +++ b/block/blk.h @@ -329,6 +329,16 @@ static inline unsigned long blk_rq_deadl } /* + * The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size + * is defined as 'unsigned int', meantime it has to aligned to with logical + * block size which is the minimum accepted unit by hardware. + */ +static inline unsigned int bio_allowed_max_sectors(struct request_queue *q) +{ + return round_down(UINT_MAX, queue_logical_block_size(q)) >> 9; +} + +/* * Internal io_context interface */ void get_io_context(struct io_context *ioc);