From patchwork Thu Dec 1 06:25:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9455495 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 A714160515 for ; Thu, 1 Dec 2016 06:25:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 976B028489 for ; Thu, 1 Dec 2016 06:25:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 889A22848E; Thu, 1 Dec 2016 06:25:39 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 D816628489 for ; Thu, 1 Dec 2016 06:25:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753431AbcLAGZh (ORCPT ); Thu, 1 Dec 2016 01:25:37 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:11202 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750847AbcLAGZg (ORCPT ); Thu, 1 Dec 2016 01:25:36 -0500 X-IronPort-AV: E=Sophos;i="5.33,723,1477929600"; d="scan'208";a="38324639" Received: from mail-by2nam03lp0056.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) ([216.32.180.56]) by ob1.hgst.iphmx.com with ESMTP; 01 Dec 2016 14:25:35 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5lA0tmoduAy9t2/3Tmh0ncNgzQTgDTeMXQmktfMqgbE=; b=i0njLJhxbYiFFO7O2+Fo8n+lljuv2C/nHTXfObbnK4GfUt+gs6Ltubmtp2mLDO+aJWrzGtE+k72nvJ94p5zq5UI126c5VDd3SRtr9oQhVf8TpF+3algvsb+SuBV0kGtwcwn4sJoO6oQ1NdA1NX9XgUQ4VnXugvNxKJD1uOuXzk4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Damien.LeMoal@wdc.com; Received: from washi.fujisawa.hgst.com (199.255.47.8) by SN1PR04MB1983.namprd04.prod.outlook.com (10.166.69.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Thu, 1 Dec 2016 06:25:31 +0000 From: Damien Le Moal To: Jens Axboe Cc: linux-block@vger.kernel.org, Shaun Tancheff , Damien Le Moal Subject: [PATCH v3] block: Check partition alignment on zoned block devices Date: Thu, 1 Dec 2016 15:25:23 +0900 Message-Id: <1480573523-30381-1-git-send-email-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [199.255.47.8] X-ClientProxiedBy: BY2PR13CA0009.namprd13.prod.outlook.com (10.162.223.19) To SN1PR04MB1983.namprd04.prod.outlook.com (10.166.69.143) X-MS-Office365-Filtering-Correlation-Id: ba2ff559-de29-4410-ac48-08d419b2da47 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:SN1PR04MB1983; X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 3:FN9nRtLY2AD8XEbodoGG5O+3PvSuww71Xzb4aR12wHyitE4OVEYFGN2askhTdhai6J/UO/k82nMc+cvljyP9pj4fA3+6tAPl6fOc8vpXJsIUyKMz1t7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DkwlMKJ3f35/QNx3vOjyHQoyPVQauIDPZ49ca1XofAnqnk8t4ReKUfkKAbtW5Flre8Xg4LUOCrftnQ2BmzPxtbeyfRODZc5iqmLOcqE+qkEHyuTlEHI0oRpAGIcPG95KSOG8LvwTF/u/CoiICbutYjmP2drI3PdVO3KfaCnH4qzpkXYAqqSfyGKdfdv3Jz3A1owXOwjx+wVTEQJsyREYbWcsuOFiqKrCxiQBoPiMwmSTsDlteF9O+9YbfhttJCuxpoxJd9S2hiHFHZ19qIIN4kemfwzL+mHfsj2urUZpMScoTppyQr3cvhye3zTazrSdEc3yH68F7cXvGNiG8HsC8iNyd0TH9SnT1ZyzcCRKQqcWmmFEUnce00SChDRfpeYFUlhpIfrIvCJ7F X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123564025)(20161123555025)(20161123560025)(6072148); SRVR:SN1PR04MB1983; BCL:0; PCL:0; RULEID:; SRVR:SN1PR04MB1983; X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 4:mrTot8Zs1/SQ46DlB7A1NjpDDAEsCwD57F9tF99f2Dtxe8YloaRnGDMgG5WPwRnI89rUcFUgZyAQwSr6Fh7n0wDnpBykND6fvVPt2hEPowCSc7VrckBptcl5f2djtp2YBcOyO8AepVXQ+KmCC1Wq9HpHoaercCr1h6VUGPA1nDbzi6Sn00C6I0oQc08t1kXDSFCSO/xFJ6+trhf99IBoxuTXw1bBM311QrdyYcWOxIgxj7cPpHJuMQWJJpo3ACe+xRHl12LZqgv3OqYGhR23juwWxemkWDn8mVYGu+PHio0iKOnW6kCcecee/N+XltWgo8dRHkD5QHMznFNqJIgc9HoKGKByW/S3/lf2YFzhXZzTyf+XqW5ypAr9qPIaXe5NfAYyhCRFYVFA3H8zZ2+MZzkwXZgz5vKvygiJKHbuwXsMLYd8lIV+1sc0GPJD3bti7KUcErTf9//Ma8HJ7ORUAYnnupqxbnAfBEuotiQwNsw/OCqugDhRLmVzSH4mzallJnDdSkzmq58lCfvOf7GI8sKor+38ECaNyNU/VK/VtQKSeDnE0Ph6VFW438xb+MKgCfOBZKRgsGDgzSNYViil8w== X-Forefront-PRVS: 014304E855 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(81166006)(36756003)(92566002)(66066001)(47776003)(5003940100001)(8676002)(86362001)(50466002)(48376002)(38730400001)(733004)(6486002)(39450400002)(39410400001)(81156014)(305945005)(7846002)(7736002)(68736007)(50226002)(189998001)(5660300001)(97736004)(110136003)(50986999)(3846002)(4326007)(6916009)(101416001)(106356001)(6116002)(42186005)(105586002)(33646002)(2906002)(6666003)(7099028); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR04MB1983; H:washi.fujisawa.hgst.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: wdc.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR04MB1983; 23:e5fzdke4qxaDbg2Vm2Q+XPgqAvfKobiPO+UVlBkSC?= =?us-ascii?Q?x3jxJvQR0wMW7KPB+ciZSH2+0iTm/6G5JNnSEJNS6Gd33QwZwzaHZiCP1D0n?= =?us-ascii?Q?9fTe8RHK6QIq4tQG1ZhSHnWEjZNx/v4iBzKZeAE4hmPqzujQWAdFQeOUeE3c?= =?us-ascii?Q?8qyQ7DCATKc/9i9KJOZ42hc8JIXFx50FVgdi+tYdQ6MADMmDaJ4hWNmTQasq?= =?us-ascii?Q?SJS7EhxojrM2H1j9vVfQnblRS9bLRpqea8213uiIgZAxmXPgS30QU1PTOG4t?= =?us-ascii?Q?2pTKsuaGPV9mTfsgBSWxxF68I6ImwtdLtr+kJuApO9ve0WCF8Q4J8EsI/7IC?= =?us-ascii?Q?fGZm3r5PLApQ3dyeFY+2Rw+ploM0H7jIgM72ByAVFXG54yvhHP+utctPZpue?= =?us-ascii?Q?PZGecKMmV7oUIxXBKrw12jUuv65vQugc+TB9/OgzLsFAYVJDFjQfW/hgAVqb?= =?us-ascii?Q?9NeGTXsaMX+dYSsxJfMfhBVj9adPkNPix99cAt1GJRIdFqXeTKu5lgp0ltqC?= =?us-ascii?Q?HCM8BuRWuiUBHazORQ59qw/Np302LckeywuK0rbS/5jGlEb+d2tBQzXBK+ga?= =?us-ascii?Q?Z+MxvqZouvqhvphHAZHNcB+QJkfV5HSXYFUVCAG7foNeGW8DZpHQW71gDKjB?= =?us-ascii?Q?q7sRIB/4sMtUYZEYOXB3ENl+II5MT6qE2WenQUEPY8NJQjVkO8AVWL6sv3Ml?= =?us-ascii?Q?yS3xrYu8KMFG30lBExGyLx/aznuYsWm/ESufSu2EGTVkEwmnYeDb7BM8eQiX?= =?us-ascii?Q?s/1qRTlk492Dw+gLdjfNb45FOv09J4l8VvX8vVAL+zDZuJGCRB1c6d1Yuyet?= =?us-ascii?Q?pngL9UymRkhCE2RWIw0e22L23WPypQfOP3d4s8GDgBrgHZnHDYMByDBVpC1r?= =?us-ascii?Q?eC7c64keIG3eb9mD/hQRJVI6z8X6eLSG16juEXign3iAqH+vFurEVY/jcR+4?= =?us-ascii?Q?biWYd6vAv0tun48Jj4Tw/q5Af6we43I2TAeUKsUYtLJQgP0AqalgjifcyQ85?= =?us-ascii?Q?oB2KhL3cBZusL69WonbGjXAS29bASvjQWCXhDt8lcVXO/8JdUYa0g+BEkLgu?= =?us-ascii?Q?9l3+n0=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1983; 6:muUE9tyaOftTzq0u1pVJIRVAs2EVCk+3FZIaQcps0GfhZV05QBQ7Oxwq83u8lrrcARPiNcT4IfFR0tUy/iFqY6WMpm35OMrZXq0K+6AM89DEwlwCTjqxJNx4seZOQgTlrvNq8IzN/P5jPmFwRDbxj4IWJMYzLf7S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mT7BWYEc9FZJPdHatoPKSdGJbzxfphjJxEfa2Waf7/3V8vgMV73KCQODFeuPYAqgo8hiUtJU0b2sf7ZOeMg/ilETaw==; 20:dxxMQbrTCyY+knYbX+YurJDisaj452F5IVETTIJ+7Du9FUgDpqOTYVZrFdFBD0cz61qOD5F0DV/yMpSkYHcRJCNT+uCjymekwMZHoBCgOUUsowGc2qnUB04fkqg7XPPj13kgyOVEq3PKpnRTa6wGasyF/LmtdduXS9OQ3AKMxwH0Ck85RFyybADeu+eU0LRSZAHyHXlWYOQjGfXG2Ico/iNnnvBbRf4S7/gWm5/REoTRBuhLFttL59OxTNPdKYqj X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2016 06:25:31.4037 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR04MB1983 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 Both blkdev_report_zones and blkdev_reset_zones can operate on a partition of a zoned block device. However, the first and last zones reported for a partition make sense only if the partition start sector and size are aligned on the device zone size. The same applies for zone reset. Resetting the first or the last zone of a partition straddling zones may impact neighboring partitions. Finally, if a partition start sector is not at the beginning of a sequential zone, it will be impossible to write to the first sectors of the partition on a host-managed device. Avoid all these problems and incoherencies by ignoring partitions that are not zone aligned. Note: If CONFIG_BLK_DEV_ZONED is disabled, bdev_is_zoned() will still report the correct disk zoning type (host-aware, host-managed or none) but bdev_zone_size() will always return 0 for zoned block devices (i.e. the zone size is unknown). So test this as a way to ensure that a zoned block device is being handled as such. As a result, for a host-aware devices, unaligned zone partitions will be accepted with CONFIG_BLK_DEV_ZONED disabled. That is, the disk will be treated as a regular block device (as it should). If zoned block device support is enabled, only aligned partitions will be accepted. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- block/partition-generic.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/block/partition-generic.c b/block/partition-generic.c index 71d9ed9..a60ac7f 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -430,6 +430,57 @@ static int drop_partitions(struct gendisk *disk, struct block_device *bdev) return 0; } +static bool part_zone_aligned(struct gendisk *disk, + struct block_device *bdev, + sector_t from, sector_t size) +{ + unsigned int zone_size = bdev_zone_size(bdev); + + /* + * If this function is called, then the disk is a zoned block device + * (host-aware or host-managed). This can be detected even if the + * zoned block device support is disabled (CONFIG_BLK_DEV_ZONED not + * set). In this case, however, only host-aware devices will be seen + * as a block device is not created for host-managed devices. Without + * zoned block device support, host-aware drives can still be used as + * regular block devices (no zone operation) and their zone size will + * be reported as 0. Allow this case. + */ + if (!zone_size) + return true; + + /* + * Check partition start and size alignement. If the drive has a + * smaller last runt zone, ignore it and allow the partition to + * use it. Check the zone size too: it should be a power of 2 number + * of sectors. + */ + WARN_ON_ONCE(!is_power_of_2(zone_size)); + if (!is_power_of_2(zone_size)) { + u32 rem; + + div_u64_rem(from, zone_size, &rem); + if (rem) + return false; + if ((from + size) < get_capacity(disk)) { + div_u64_rem(size, zone_size, &rem); + if (rem) + return false; + } + + } else { + + if (from & (zone_size - 1)) + return false; + if ((from + size) < get_capacity(disk) && + (size & (zone_size - 1))) + return false; + + } + + return true; +} + int rescan_partitions(struct gendisk *disk, struct block_device *bdev) { struct parsed_partitions *state = NULL; @@ -529,6 +580,21 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) } } + /* + * On a zoned block device, partitions should be aligned on the + * device zone size (i.e. zone boundary crossing not allowed). + * Otherwise, resetting the write pointer of the last zone of + * one partition may impact the following partition. + */ + if (bdev_is_zoned(bdev) && + !part_zone_aligned(disk, bdev, from, size)) { + printk(KERN_WARNING + "%s: p%d start %llu+%llu is not zone aligned\n", + disk->disk_name, p, (unsigned long long) from, + (unsigned long long) size); + continue; + } + part = add_partition(disk, p, from, size, state->parts[p].flags, &state->parts[p].info);