From patchwork Fri Oct 28 19:45:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 9402615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E706460231 for ; Fri, 28 Oct 2016 19:45:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D64F72A910 for ; Fri, 28 Oct 2016 19:45:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB4DB2A912; Fri, 28 Oct 2016 19:45:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56FE72A910 for ; Fri, 28 Oct 2016 19:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S942390AbcJ1Tpz (ORCPT ); Fri, 28 Oct 2016 15:45:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48246 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S942370AbcJ1Tpz (ORCPT ); Fri, 28 Oct 2016 15:45:55 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A86F421A4; Fri, 28 Oct 2016 19:45:49 +0000 (UTC) Received: from localhost (dhcp-25-156.bos.redhat.com [10.18.25.156]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9SJjmZH015450 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 28 Oct 2016 15:45:49 -0400 From: Mike Snitzer To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, dm-devel@redhat.com Subject: [PATCH] block: disallow changing max_sectors_kb on a request stacking device Date: Fri, 28 Oct 2016 15:45:49 -0400 Message-Id: <20161028194549.14556-1-snitzer@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 28 Oct 2016 19:45:49 +0000 (UTC) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Otherwise users can easily shoot themselves in the foot by creating the situation where the top-level stacked device (e.g. DM multipath) has a larger max_sectors_kb than the underlying device(s). Which will certainly lead to IO errors due to the "over max size limit" check in blk_cloned_rq_check_limits(). Use of WARN_ON_ONCE() gives users visibility into which application attempted to perform this unsupported max_sectors_kb change. This is a crude, yet effective, solution that forces the use of system software (e.g. udev rules or multipathd) to tweak max_sectors_kb of the underlying devices _before_ a layer like DM multipath is layered ontop. Signed-off-by: Mike Snitzer --- block/blk-sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 9cc8d7c..cce43d7 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -199,8 +199,12 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) unsigned long max_sectors_kb, max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1, page_kb = 1 << (PAGE_SHIFT - 10); - ssize_t ret = queue_var_store(&max_sectors_kb, page, count); + ssize_t ret; + + if (WARN_ON_ONCE(blk_queue_stackable(q))) + return -EINVAL; + ret = queue_var_store(&max_sectors_kb, page, count); if (ret < 0) return ret;