Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1038354pxb; Thu, 15 Apr 2021 12:20:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6o+MSWp5KLgCHZjV5o+ZD+j8rbhrR4MSytMEgGE8OMWbQ5BsnQFq8fjds0buxab7kTxRe X-Received: by 2002:a17:906:4c91:: with SMTP id q17mr5108356eju.0.1618514419559; Thu, 15 Apr 2021 12:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618514419; cv=none; d=google.com; s=arc-20160816; b=W8uIHDRzT5nBcJlZWwyzME6xt8rwOwZmiFTQRnYqvbFQwlVJrJ46si7bcsMK9ju4Ru vggnio6cAvNU8cgT8uQ+QinsF68loaJrZttfEFgD3m07iX+559O92V5GtpaAoReQCed+ DeXm2WmRe/04PbxflhkIxbMiXjC10FhbfLGv33KbHpTZYJnL+N1Ft0D5z6yyDpfpdweM EiVV1fFi/zvvUCvYAx+hTu8rqrzGDlDgxTcN5qHILsHWBEfafGhwYbNXZ/l/jUyd1R5C c6XwVtScTx8ZzizQ+kMZjCuRM58XOxWgEpUgUzSeiWw8cp+DRZ2CNthefnYB4x+7NOgL kW8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=2/mLy6Qs38Bvj+YcPWXxnazVy7EEcqhvZh36iJtGe/k=; b=OAnoBHruM7BK3GwR2Ef2ddntzBD+TF79FXq+5tQSD1JoZbUrca1U2KLBRSfB8Tf8g8 vGz4oF8PJunQuim9mwSTTMx2G+TNLlnwyJXTdJnoa765FBmsqHDQl2KZJiwXmx/HHJMW b+0L5SuvYQFjWuQSpSukmlePfnDfruijVRl1dsoFeYgpoUI9KhHg77MohDVMyact21bY eOIinvaohj8KYR5q+TyCDUPLnBHQrx+5ECPylzP88R9yUT8/r7KQ9iRo7btYgUfEWnQ3 IInRUoJXtrFCWfjEGRmAtBH9GM30WCjp0yWW+MJS214e+/FO01pPC+uh8409hUt9O8fs 6PSA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds10si3512139ejc.719.2021.04.15.12.19.55; Thu, 15 Apr 2021 12:20:19 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234825AbhDOTTV (ORCPT + 99 others); Thu, 15 Apr 2021 15:19:21 -0400 Received: from mail-pg1-f173.google.com ([209.85.215.173]:36678 "EHLO mail-pg1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234505AbhDOTTT (ORCPT ); Thu, 15 Apr 2021 15:19:19 -0400 Received: by mail-pg1-f173.google.com with SMTP id j7so8158195pgi.3; Thu, 15 Apr 2021 12:18:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=2/mLy6Qs38Bvj+YcPWXxnazVy7EEcqhvZh36iJtGe/k=; b=RnVSwskXBY+Tw3xUCKBZDp7ZakDj+QRRP4bwpoeVxqDc5ROd9oMlD1MaPpbzoOAurl p6WmJTtMLuH9SowsSK2PpDZpQJ+R0VgOu6oO2h6uvB3HgsEeMs1xfXXTxmofQ0ULX9pA ZJrPcwHWk7E4jI8zFS3SHfNHydLV+MD7nTwl/pzsbEaCaf4Bt6jwHKzR7l/YqbkL2EOY TObDuanFtLGmAlUcvyXxOjd+PWXYjakdOsCBOLvTCoqz4GeF7ZQcuAlRofuqEXeESTrF MqU73vCze2gaecim0JnCkikWG7pOqXO+ZWqFXLmdcQ7tD7otAR9mxPWACF1yh6vSz/NF bo2Q== X-Gm-Message-State: AOAM533XG8ZGUxDUftEWpyjsTEcI/iYiYfkbnCzSITGngzFNJR4B2QxE X2QQsyYlR6S3DghLr7X9HgI= X-Received: by 2002:a65:6704:: with SMTP id u4mr4763609pgf.169.1618514335629; Thu, 15 Apr 2021 12:18:55 -0700 (PDT) Received: from ?IPv6:2601:647:4000:d7:f031:1d3a:7e95:2876? ([2601:647:4000:d7:f031:1d3a:7e95:2876]) by smtp.gmail.com with ESMTPSA id p22sm3154516pjg.39.2021.04.15.12.18.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Apr 2021 12:18:54 -0700 (PDT) Subject: Re: [PATCH v7 1/3] bio: limit bio max size To: Changheun Lee Cc: Johannes.Thumshirn@wdc.com, asml.silence@gmail.com, axboe@kernel.dk, damien.lemoal@wdc.com, gregkh@linuxfoundation.org, hch@infradead.org, jisoo2146.oh@samsung.com, junho89.kim@samsung.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ming.lei@redhat.com, mj0123.lee@samsung.com, osandov@fb.com, patchwork-bot@kernel.org, seunghwan.hyun@samsung.com, sookwan7.kim@samsung.com, tj@kernel.org, tom.leiming@gmail.com, woosung2.lee@samsung.com, yt0928.kim@samsung.com References: <2e54f27a-ae4c-af65-34ba-18b43bd4815d@acm.org> <20210415103820.23272-1-nanich.lee@samsung.com> From: Bart Van Assche Message-ID: Date: Thu, 15 Apr 2021 12:18:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210415103820.23272-1-nanich.lee@samsung.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/15/21 3:38 AM, Changheun Lee wrote: > @@ -167,6 +168,7 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto > max_sectors = round_down(max_sectors, > limits->logical_block_size >> SECTOR_SHIFT); > limits->max_sectors = max_sectors; > + limits->bio_max_bytes = max_sectors << SECTOR_SHIFT; > > q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9); > } Can the new shift operation overflow? If so, how about using check_shl_overflow()? > @@ -538,6 +540,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, > { > unsigned int top, bottom, alignment, ret = 0; > > + t->bio_max_bytes = min_not_zero(t->bio_max_bytes, b->bio_max_bytes); > + > t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); > t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); > t->max_dev_sectors = min_not_zero(t->max_dev_sectors, b->max_dev_sectors); The above will limit bio_max_bytes for all stacked block devices, which is something we do not want. I propose to set t->bio_max_bytes to UINT_MAX in blk_stack_limits() and to let the stacked driver (e.g. dm-crypt) decide whether or not to lower that value. > diff --git a/include/linux/bio.h b/include/linux/bio.h > index d0246c92a6e8..e5add63da3af 100644 > --- a/include/linux/bio.h > +++ b/include/linux/bio.h > @@ -106,6 +106,8 @@ static inline void *bio_data(struct bio *bio) > return NULL; > } > > +extern unsigned int bio_max_size(struct bio *bio); You may want to define bio_max_size() as an inline function in bio.h such that no additional function calls are introduced in the hot path. Thanks, Bart.