From patchwork Tue Feb 2 07:06:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 8187261 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AD6A59F3CD for ; Tue, 2 Feb 2016 07:16:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F3B1A20253 for ; Tue, 2 Feb 2016 07:16:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04AD72024D for ; Tue, 2 Feb 2016 07:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752796AbcBBHQ3 (ORCPT ); Tue, 2 Feb 2016 02:16:29 -0500 Received: from sjc00mx1.hgst.com ([199.255.44.36]:13438 "EHLO sjc00mx1.hgst.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752513AbcBBHQ2 (ORCPT ); Tue, 2 Feb 2016 02:16:28 -0500 X-Greylist: delayed 604 seconds by postgrey-1.27 at vger.kernel.org; Tue, 02 Feb 2016 02:16:28 EST X-IronPort-AV: E=Sophos;i="5.22,384,1449561600"; d="scan'208";a="182736975" Received: from mail-bn1lp0144.outbound.protection.outlook.com (HELO na01-bn1-obe.outbound.protection.outlook.com) ([207.46.163.144]) by sjc00mx1.hgst.com with ESMTP/TLS/AES256-SHA; 01 Feb 2016 23:06:19 -0800 Received: from SN1PR0401MB1710.namprd04.prod.outlook.com (10.162.131.12) by SN1PR0401MB1709.namprd04.prod.outlook.com (10.162.131.11) with Microsoft SMTP Server (TLS) id 15.1.396.15; Tue, 2 Feb 2016 07:06:18 +0000 Received: from SN1PR0401MB1710.namprd04.prod.outlook.com ([10.162.131.12]) by SN1PR0401MB1710.namprd04.prod.outlook.com ([10.162.131.12]) with mapi id 15.01.0396.020; Tue, 2 Feb 2016 07:06:17 +0000 From: Damien Le Moal To: "linux-scsi@vger.kernel.org" , "linux-block@vger.kernel.org" Subject: blk-merge: BIO front merge size check for chunked devices Thread-Topic: blk-merge: BIO front merge size check for chunked devices Thread-Index: AQHRXYg2QoK+KfPN5UumX1VvKzTmvw== Date: Tue, 2 Feb 2016 07:06:17 +0000 Message-ID: <7A8F97E9-36F4-43C8-9646-895B818C632A@hgst.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/0.0.0.160109 authentication-results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=hgst.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [111.99.34.114] x-microsoft-exchange-diagnostics: 1; SN1PR0401MB1709; 5:onJNSASnnB3tds6OyEkA3qSzySGdRUToMy3ybkjZ5HO6OVdkGGranLpasgdywOolvxbc51RfEO33A+1psRAe8xBSVG4yfuXxlvxaW8FmbeiJ3G7fCDB4FpdgZaLsr1YWxcnYljlTIr/5StKNmaCylw==; 24:4Elfgtmmll0AfPWj/uA0/tuoU9pCTNH6OhD/aX0Vyo7Yd4CPPBXyGgDbYASEJ1VRkakW/vaVmgxRu+ETzFbv5DbxbJlWV9Ch4xxXupf0FmI=; 20:Ybzl1YbAGAjY6/YRGfuXV4LhJCNY+ZUKLv0SXy5MTj24FAPndsz3RGC2EnhzhK1B2DX1xtnjxcgRArZtg9w0HY4TcjRr3ES5GnW37jwp5D1L4vMfQaaq9o/7B1iX5nYZOPNnRcY7i1IkvUeEY5EU0Oj89gEjEypANpq6qg6cGslWyE9Bn06uYl5Zyxn8Hzl4/4PBDATHzQ4Jm1EVZlxpxKjVl9shcP7wmobUAcGNwRITqeBe7OFBIfmdZnqEXlPr x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0401MB1709; x-ms-office365-filtering-correlation-id: de1839cd-3eba-4251-b035-08d32b9f58d3 x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(102415267)(102615245)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:SN1PR0401MB1709; BCL:0; PCL:0; RULEID:; SRVR:SN1PR0401MB1709; x-forefront-prvs: 084080FC15 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(229853001)(83716003)(33656002)(4001350100001)(5001770100001)(54356999)(586003)(189998001)(99936001)(3280700002)(1096002)(87936001)(77096005)(40100003)(36756003)(2501003)(2906002)(5004730100002)(1220700001)(122556002)(5890100001)(2900100001)(99286002)(86362001)(66066001)(5002640100001)(6116002)(10400500002)(92566002)(5008740100001)(83506001)(106116001)(5001960100002)(450100001)(50986999)(102836003)(107886002)(3846002)(3660700001)(82746002); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR0401MB1709; H:SN1PR0401MB1710.namprd04.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hgst.com X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2016 07:06:17.7403 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0401MB1709 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hello, In ll_front_merge_fn, the request size result of the eventual front merge of a BIO with a request is checked against the maximum size allowed for the request using blk_rq_get_max_sectors. This function will also check that the merge result will not span block chunks for chunked block devices using the function blk_max_size_offset. However, blk_rq_get_max_sectors always calls blk_max_size_offset using the request sector position, which in the case of a front merge is not the position at which the merged request would be issued: the sector position to use must be that of the BIO, and not that of the request. This problem can trigger a “boundary violation error” for write requests on ZAC/ZBC host-managed SMR disks as the last write BIO of a zone (a chunk) can end up being front-merged with the first request of the following zone (chunk). The attached patch against linux-4.5-rc2 fixes this problem by adding an offset argument to the function blk_rq_get_max_sectors. Best regards. Reviewed-by: Hannes Reinecke --- Damien Le Moal, System Software Group, WW Research, HGST, a Western Digital company Western Digital Corporation (and its subsidiaries) E-mail Confidentiality Notice & Disclaimer: This e-mail and any files transmitted with it may contain confidential or legally privileged information of WDC and/or its affiliates, and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail in its entirety from your system. diff -Naur linux-4.5-rc2/block/blk-merge.c linux-4.5-rc2-patched/block/blk-merge.c --- linux-4.5-rc2/block/blk-merge.c 2016-02-01 11:12:16.000000000 +0900 +++ linux-4.5-rc2-patched/block/blk-merge.c 2016-02-02 15:28:07.626107509 +0900 @@ -504,7 +504,7 @@ integrity_req_gap_back_merge(req, bio)) return 0; if (blk_rq_sectors(req) + bio_sectors(bio) > - blk_rq_get_max_sectors(req)) { + blk_rq_get_max_sectors(req, blk_rq_pos(req))) { req->cmd_flags |= REQ_NOMERGE; if (req == q->last_merge) q->last_merge = NULL; @@ -528,7 +528,7 @@ integrity_req_gap_front_merge(req, bio)) return 0; if (blk_rq_sectors(req) + bio_sectors(bio) > - blk_rq_get_max_sectors(req)) { + blk_rq_get_max_sectors(req, bio->bi_iter.bi_sector)) { req->cmd_flags |= REQ_NOMERGE; if (req == q->last_merge) q->last_merge = NULL; @@ -574,7 +574,7 @@ * Will it become too large? */ if ((blk_rq_sectors(req) + blk_rq_sectors(next)) > - blk_rq_get_max_sectors(req)) + blk_rq_get_max_sectors(req, blk_rq_pos(req))) return 0; total_phys_segments = req->nr_phys_segments + next->nr_phys_segments; diff -Naur linux-4.5-rc2/include/linux/blkdev.h linux-4.5-rc2-patched/include/linux/blkdev.h --- linux-4.5-rc2/include/linux/blkdev.h 2016-02-01 11:12:16.000000000 +0900 +++ linux-4.5-rc2-patched/include/linux/blkdev.h 2016-02-02 15:26:39.313283902 +0900 @@ -888,7 +888,8 @@ (offset & (q->limits.chunk_sectors - 1)); } -static inline unsigned int blk_rq_get_max_sectors(struct request *rq) +static inline unsigned int blk_rq_get_max_sectors(struct request *rq, + sector_t offset) { struct request_queue *q = rq->q; @@ -898,7 +899,7 @@ if (!q->limits.chunk_sectors || (rq->cmd_flags & REQ_DISCARD)) return blk_queue_get_max_sectors(q, rq->cmd_flags); - return min(blk_max_size_offset(q, blk_rq_pos(rq)), + return min(blk_max_size_offset(q, offset), blk_queue_get_max_sectors(q, rq->cmd_flags)); }