From patchwork Thu Dec 1 07:00:25 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: 9455511 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 D512C6074E for ; Thu, 1 Dec 2016 07:03:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6CB928484 for ; Thu, 1 Dec 2016 07:03:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B957D2849F; Thu, 1 Dec 2016 07:03:46 +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 1EEA228484 for ; Thu, 1 Dec 2016 07:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751463AbcLAHDp (ORCPT ); Thu, 1 Dec 2016 02:03:45 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:24196 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750856AbcLAHDo (ORCPT ); Thu, 1 Dec 2016 02:03:44 -0500 X-IronPort-AV: E=Sophos;i="5.31,723,1473091200"; d="scan'";a="41877558" Received: from mail-cys01nam02lp0047.outbound.protection.outlook.com (HELO NAM02-CY1-obe.outbound.protection.outlook.com) ([207.46.163.47]) by ob1.hgst.iphmx.com with ESMTP; 01 Dec 2016 15:00:37 +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=ZAjUu58EVMd8tiQ7gD1fsPu3Q6wfs423GnbYAOL4+MU=; b=G1d5uDqAUQ50QiEy9KoeP0DDB1tTupwHgQb4TNGz51O5F7TJez+Gd1uNANzop+IWn0rG+w9lO1GEKmdEFlDS6ZXxi2RjjHK8S+dVGyyj1+au00sETt3CnYhX3Wxy8wuzgf4puTGpVeZqPNZkkImhsbQVfAaP8yknvCB9lL9wGoA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Damien.LeMoal@wdc.com; Received: from washi.fujisawa.hgst.com (199.255.47.8) by SN1PR04MB1982.namprd04.prod.outlook.com (10.166.69.142) 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 07:00:33 +0000 From: Damien Le Moal To: Jens Axboe Cc: linux-block@vger.kernel.org, Shaun Tancheff , Damien Le Moal Subject: [PATCH v4] block: Check partition alignment on zoned block devices Date: Thu, 1 Dec 2016 16:00:25 +0900 Message-Id: <1480575625-32134-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: BLUPR15CA0065.namprd15.prod.outlook.com (10.162.95.161) To SN1PR04MB1982.namprd04.prod.outlook.com (10.166.69.142) X-MS-Office365-Filtering-Correlation-Id: 8222f9ea-1f58-4b30-46bd-08d419b7bfb0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:SN1PR04MB1982; X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1982; 3:LO9whhRmbPNlDKTqiEzM/PDPLbkNG0wNV2SdibVy/jhSQEYQXOA9QmTeiV5gEOgJSoc/uVDmMjuYl6Wh2vEmC1TecPZ1aleOfVj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AfzRdVH9COg4wlt+nvS9YshGx2qVfphAgHXs1MQycmc5USH7oW7Pa53a9NiVE3SX3XnfrbeFq9OuNpHFwPehwSmEE+CnPFIXT/wzOyKu6jWi1f5qcidsXG3DoBJmi9TKpe2kEqereAHmxpq6sE7r5CzSlnjQDhlrx8Y4POLBgcHw9xPhEsxklK5iMD/yRY7gz019cqLsfL0yBZrkwFYe9+hFVEbd1KSAEWfH2HtZtKnigZK72qUfoQ==; 20:7xYE/uiJK8LGRXPFYZRSxQDJB63mMUkvr2IB4nxED3mkq+1P/5YM4tgZwpr2wNDyKgfNzF0Vb6O6HVxgTGDPPPzys+A+TeLJbIBpYJJ9MOPDCfrEksLTW4IHS3hg4oSl3qEuWKQxZuL2m/b9Q/shkk7xI1m0Oxe9kKdT3C7zggBcqfXlKEOPmXmA6hBvfVjrSjCxxS4gqmxPhAXpewKxGlQ4HucPgFCrh1IXAStYp7tmDV35nj2ODdEKR516lMA1NBq+GRiQsvdtJ6X05g+yCCFjzKbjxmdWAJz3n/Eqh28n+XAViqfM2dN2FSsqjlRoLnjOBZ4VnCu/K9tPVkvqY3i5ZKGwhhi6eys6hRzRJn33GtFBoOJLQ1/WUhE/JPs98BksCIdr1NEDRmvvruLW1vyhdRdPQoT6jHQ0L+wOlwbCiLznCGoAJgtbnXV4wjG0vbiQdO3qGUUY+xVBFxIPzebGjtBnFqwMkplWHYuxsN6AZ0fVsg4OnVBAkCF3Gooo X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123555025)(20161123558021)(20161123564025)(20161123560025)(6072148); SRVR:SN1PR04MB1982; BCL:0; PCL:0; RULEID:; SRVR:SN1PR04MB1982; X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1982; 4:DVgDq+qjltPSiPs5us2A7cOBbEGewSdPBdVA1qrxyUHAktzofj+jKi1FGYdSRuSKKSpyJX6alxHeAk/9KbRUiNCeUvk8l8hegTiQGyvSZLmGTsN7o7hc9d843wVcP6Es8NdZm0XNlN/X8aIiCPFUPqbjDX4UOhoDrMkddwcqvRCgk3DiedInZiTzM2UlR73vep4L4Lz9sU4glxf+GPtsQ0OY+g1gZ+UVCEwP1fa75gTL/a18oNpYJ7aiAlccRESXhwbfLVMxfdH+ssq0b5qmBcwi/PK7ly94QBrrXwq7PnNYFPpiP/0G2TyqhYd3IxXkyGwvU7nikrsEsQxpR8NkQ61zz0g29WYD4Oi5K5eCqzQ4Wx2FhRGKac4psDRkbXNt8FnWWQW59D9Bi1YtvZ59vcnAubZJtAFD6CLv0ntCFcu1gXq1J1Ri2jbOtb0HuCbfQ3TvjniVlTOVyEFF6RcRyi6bZwiiY/gpEdO3lLNEX6Y/nnpRoWuAaw6DCb1oOYrriwCkICfFlkT5TEGqpzRkEupU2DFaR/ZKtbxm16IM6Lw6bBeQvN9XO9IyCJaDqrNmW3Y4m1ePnGT8HsM7K8s2Rz+qUgQVYgwgUh5bUDYR0kVdXvFwQsIxu+Cfx7XgwKJr X-Forefront-PRVS: 014304E855 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(7846002)(66066001)(305945005)(47776003)(68736007)(92566002)(101416001)(33646002)(97736004)(7736002)(50986999)(86362001)(6116002)(3846002)(42186005)(36756003)(733004)(6486002)(5003940100001)(39450400002)(105586002)(39410400001)(106356001)(6916009)(50466002)(189998001)(48376002)(2906002)(81166006)(38730400001)(4326007)(5660300001)(6666003)(50226002)(81156014)(8676002)(110136003)(7099028); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR04MB1982; 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?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q0TYXU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR04MB1982; 7:TXL9uh+CWO255WJ87cUwFnc5hX2WTMgR8BKKjP1oNs7gknPtz5mPdB5+nK/PFlGuMcbXEPbSijMiAfzs7Z45k8JCL+Ry1A0hnt6m97mRk0Y0E9r/1gystqAdd2wM4PQVKhXlTJ2qBPYp0HhVAEDudyZXEoYgY4+UxcFxX9EnPt0eSPhazOD2zg87ME1545njZNFZaG0SLg9kN8hB7N6m+UHT64zNDKTyjFO6BrksfD7+D1QQEtevMnS9qfVK1WDFWqCXm10B0maVSfHIg84hAquTYPGeNeKpZDoa/ZqN/+5jh1ZvHfoDFKRZ+2w8+dUnbvXWF5gDsuTrzJ0uEKg1+2Iw8LW9iOcZSnPV3ETGrASMPMs5EJSlfUg3pbCSg+KOVtjqL8Y8mKypuyh+dFxl8gd9ttLx78nB0KyEoRLb8gl+VyyhSpydIUPGHFXP7at8sl2xDkpSB5BHZQb8N5/JCA==; 20:i+J9ahVG6vcdeBBbmbunmzF3vdnm3Uxa0hFRSm7t/kgzJSRBc6bPLmyYEofjJUqHqUzg+aU43hC4tPAuqbnoa+RhlvWTVhcwFx011YnTHZsKBh05xsYUg5j1IyNnRltbgh55erNooTklJQb8e71kMkSOFPtHwZpB2xB2HGjvVkZiCq5kv5vO6bqLivHA5NyodI+qdIfa4YvEiKZy20wSZk9YOJrRK3g85/0SKFMq0HS6Q7r1B8LQQrAYwUkqIpK/ X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2016 07:00:33.9933 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR04MB1982 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: Even with CONFIG_BLK_DEV_ZONED disabled, bdev_is_zoned() will 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 | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/block/partition-generic.c b/block/partition-generic.c index 71d9ed9..d7beb6b 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -430,6 +430,56 @@ 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. + */ + if (WARN_ON_ONCE(!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 +579,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);