Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp1973455pxb; Sun, 10 Jan 2021 18:52:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWtp5Slm885LO3pz4kjdZ12FM7xwQaz6DMSSuw3j855afSNFAK5F4XFBBRJJDt3W+BtR+k X-Received: by 2002:a50:9ee6:: with SMTP id a93mr12878498edf.174.1610333524776; Sun, 10 Jan 2021 18:52:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1610333524; cv=pass; d=google.com; s=arc-20160816; b=pbSae6WLLgSQJ15EQge1Tl+OE2je4cyDBfrL433eSccoRIH04i5DMZcYu9hOiQmvqw jTbFxZiz7NNEB4ewNrAEx23PMr3bMjxvlnOgl+AHXGya6NkLf5iLNxSY1s545pzre4by 3IEwMw5kWi7II7kHhcsRmqbOU1cqi3Vdz2VJzXjq77q/9i0QeDRFaWQo59gAVm/vCyGr 5KbSGfeEH+lJFCYONj/V+2V2YjpyrrRzBPjF4UuE2q3rZmuuosJDfr1L+22hlQHHfMqr aHtBv5FetBwEF9xvHZ3EchQflniLtWA1g+ysyY3CWpflTI2oyszS3Yj73+UBaIcU4R47 lzfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :wdcipoutbound:content-language:accept-language:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature:ironport-sdr:dkim-signature; bh=clbEmvVlAnF7drGq9kT7b20vaw60EOtEmgOkTRFukho=; b=iRfbNQ+ejQor21hdP0YHLvpPKyPML/6DBYmDcniG/bMC4dKCiFXO6/HFKcLm5mdIkd Niol2OkqkNDTRuedixdQODkXc1iPjADCJTS450oJbBHnfiuP5nM4fM9U1QjurMbifYSk hlYfwMSNgdzEU9aia0Teb6n2lpgY1eP5wJsicV5shmEZ34vpqBv8tIEcJQkFigTOm4ff aQGkausWfPJnKBczi4J2lrZ1xBOSlPKPkND1Ba1hQnUPRwT9Y7ANf2l0BWiAlRrMEiMN gNZ0LWqHb6Vldq1+NK4+isqlJFExZMIT3hYWSyvNcUqSJDERG44wOqd2jOpn5j+UkIQ5 JCfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=TBWI4w+T; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector2-sharedspace-onmicrosoft-com header.b=bUe7bJbX; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t20si6005861ejd.719.2021.01.10.18.51.40; Sun, 10 Jan 2021 18:52:04 -0800 (PST) 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; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=TBWI4w+T; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector2-sharedspace-onmicrosoft-com header.b=bUe7bJbX; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726720AbhAKCsJ (ORCPT + 99 others); Sun, 10 Jan 2021 21:48:09 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:53582 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbhAKCsI (ORCPT ); Sun, 10 Jan 2021 21:48:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610334310; x=1641870310; h=from:to:cc:subject:date:message-id:references: content-transfer-encoding:mime-version; bh=hAxuyY4Vixf+dp4TqEvE1evcq4308tPELmMANXkH3TY=; b=TBWI4w+T8piwVK5Pz5sn7p/1rzeh+XsN8NtLQcGizz+GLbCxlecchtzM zcX7415+Ob9gm/5tMDYlYJ50tPrq/htABrTyJmh3VkyLBWygn4VKj7eM9 0SgWqziiHVC9PQbUBdv5dS9L3jkyGqr7Wyvkkqkha5cljlaC2/dvAXHLC shFItLf5wH+p5mhCBrV6bwHrh5Oqpz5NhLs427t4LkaGzPtR4DkPFIbqB bwzH1v4NiIvUjV4W+6IDNK75QLnAOkP5WrGl/JI7w3wIANS6iaHj7Fmzi 0BO2G4eOeKdpxNyYGSX/YphiAK5L9nRM1rIzmYuTm8UDoEtLuy0J8UdIi Q==; IronPort-SDR: Bfa3TkHetboTo4pGEQyuCOTNvltjitgjtf9YgfRwgT9rcKbgJ36knbTvGFXOVQXvqWZvHnlfif kGsmNaTwQjfBAxZ/zj7JeanMrMuiWlFhpbk6tfSI4H8OvR2F8YsYodUA0e34flzdkho0/90CWn ThETUehs01kf8A7yQygBqd2Z2fQMsvaIkoPgo0HXg0nsKKsTFWZHc2X2LsjutoXUSbs53wkyOf AlS6T5S83BmMABBiiuFZXJ5OuBqEKtoH7UCYtPrHmeEwqTuUJYR8LpgaEOkmLBC7kDkXp29Qcn V+g= X-IronPort-AV: E=Sophos;i="5.79,337,1602518400"; d="scan'208";a="260999465" Received: from mail-co1nam11lp2169.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.169]) by ob1.hgst.iphmx.com with ESMTP; 11 Jan 2021 11:03:30 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jjVYq/QMM6r9Yn6yQcN5Nxnh6c6/C1E9cPhUUUmDlou4PBa/aOs5pU32c/WpiP+Bpu+Iid7Rv9Gf4pD7FHsVSBpR4M9HHWScDBD30Rin06r8WeTPCsm4GZXaNZX083VQssxISDWVsYC/zyz9RLsCalOj4809/Bp3xOkZEAYNzkgjoiHFAdn9t+fQPR9Xao1/YuWUBX732npdQRIVdaJ2maY9UCd2HcZfjOMRMI5haPjO6L+Jk2ZM2PjvgNG3zXbDAsH5k1uI3tipmQfM3dxJaC74RokC04+gsnhCuZWm7qVNqkDxTJW8Ru79P4jxbpAfYYPB2qBG0joXThw/m6qy3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=clbEmvVlAnF7drGq9kT7b20vaw60EOtEmgOkTRFukho=; b=FCFdpfQqdzIgc8bTAJovuATBkcFxHFqzu0ka7KezvJCFfxMEjZ9p4qmPos9+ANgCcMNP8wR1PEJ5W/sSpVklwqnU4qgvczthWpSo36bWoLJvVjnsT0F5scbH2bHk4ye2dnVOtNRu8+g0NQs/orZyfu0vceMvXtOff7o8PbRN2/0z2Wrj+vDJSLYYXilWm7/6PX1RJ1+CheFohkZKldZn+ML3wwbVFZkHHdiZp0ZvpGU/Y45pY/eQUg316vEren85/pFZN1eDmwu1b5dlNahrTFBYWqI+4hzy2MHK7R6RnbXPBztnF0O/Wl5y1ydzKGkDCq56Y0F9aYUHJctn7ymExw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=clbEmvVlAnF7drGq9kT7b20vaw60EOtEmgOkTRFukho=; b=bUe7bJbXU8oulg3PDfahXwiH/RbrkgvjxFFy7LnYMSFGmv2J51ACELha0sS3KFmTtviiwdyXI+aqzttIh+HwTsKxkJLTPXeYi0dQBg0WVKn19Gta5UVqCOQic1jmqn81OddaTbO4i7iABpAJy475XVlBGlhD8c6IQI25LHCPjC8= Received: from BL0PR04MB6514.namprd04.prod.outlook.com (2603:10b6:208:1ca::23) by BL0PR04MB5089.namprd04.prod.outlook.com (2603:10b6:208:5e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6; Mon, 11 Jan 2021 02:46:58 +0000 Received: from BL0PR04MB6514.namprd04.prod.outlook.com ([fe80::2dbb:7e01:f076:eca0]) by BL0PR04MB6514.namprd04.prod.outlook.com ([fe80::2dbb:7e01:f076:eca0%9]) with mapi id 15.20.3742.012; Mon, 11 Jan 2021 02:46:58 +0000 From: Damien Le Moal To: Pavel Machek , Greg Kroah-Hartman CC: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , Naohiro Aota , Christoph Hellwig , Johannes Thumshirn , Jens Axboe Subject: Re: [PATCH 4.19 13/35] null_blk: Fix zone size initialization Thread-Topic: [PATCH 4.19 13/35] null_blk: Fix zone size initialization Thread-Index: AQHW4rJrXEheF1syA0iwzTfipJ4Neg== Date: Mon, 11 Jan 2021 02:46:57 +0000 Message-ID: References: <20210104155703.375788488@linuxfoundation.org> <20210104155704.049016882@linuxfoundation.org> <20210106125449.GA7589@duo.ucw.cz> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: ucw.cz; dkim=none (message not signed) header.d=none;ucw.cz; dmarc=none action=none header.from=wdc.com; x-originating-ip: [2400:2411:43c0:6000:b89f:834c:8952:cf2d] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: e2b1e79f-cf03-41ae-a46d-08d8b5db2a18 x-ms-traffictypediagnostic: BL0PR04MB5089: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: wdcipoutbound: EOP-TRUE x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3lP2tGPPvymHiYWBma5r+ztdCor9q4uD1sATkUPMoloo7Enf1xnxnvblY1Mke8khQAVaH9zeXM8baZ7HX9Vn9oGud4kPNLpGWq4StfAKLDWuGimebyPBewKCIJh74UtaFstnEwheRE36Wlo9KGrt/OX8BYV3PdKZLD9PANOTdxX59orb0+BXZYMaxibvlvPt4jZa1hx5HATjWPXLgzUd9S/B2aYSC3sj14mqlwMYNhYiq5bwEptowwmuQiuNl/uZgBEkZgoNk4j9qdZYSnEEUKMvWjc6b4y2uN3R1xy7V88Nsc0OclT+pBMdJR8wzkSVDzzeQ5YW1auC/WhA5zjEYJLZWCWJe8fpgeteJi/lC4CEYR5cAzCzidaaEDxdKyzlMouzMyAFqWAaGaC67yqPKQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR04MB6514.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(39860400002)(366004)(136003)(376002)(396003)(52536014)(64756008)(7696005)(86362001)(66556008)(83380400001)(54906003)(2906002)(33656002)(5660300002)(66946007)(91956017)(76116006)(53546011)(66446008)(110136005)(316002)(71200400001)(66476007)(55016002)(8936002)(478600001)(6506007)(4326008)(9686003)(186003)(8676002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?8F1XRHOZb9QYQm6Yr1zKFb3KRlm6NhHWArSIGbOLiDNKb2QFUKRa4kwl3mRZ?= =?us-ascii?Q?C0bgG8DuFsu0KTj0TaJWpsC3Tw/42c7RXVmaeLfTUrv4f4yRUNG3coPsWVsV?= =?us-ascii?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Wt9h26tthn8PKTzHkte4D0?= =?us-ascii?Q?h/w2nHTzboRi6vm2j7NSm+Lm9NpnV5+cYsKOkXTfI1WHiutK06ks4ZtqWrHh?= =?us-ascii?Q?sWzOSoX1?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BL0PR04MB6514.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2b1e79f-cf03-41ae-a46d-08d8b5db2a18 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2021 02:46:58.0025 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: m6pksFCko5aUkBx1BlSXKM2pbzp2S8D8tHzzby47HHkx0WSc0nyp8M3vtAdiiCdey4QaP9rdQF2hbtKxODngug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR04MB5089 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/01/06 21:55, Pavel Machek wrote:=0A= > Hi!=0A= > =0A= >> commit 0ebcdd702f49aeb0ad2e2d894f8c124a0acc6e23 upstream.=0A= >>=0A= >> For a null_blk device with zoned mode enabled is currently initialized= =0A= >> with a number of zones equal to the device capacity divided by the zone= =0A= >> size, without considering if the device capacity is a multiple of the=0A= >> zone size. If the zone size is not a divisor of the capacity, the zones= =0A= >> end up not covering the entire capacity, potentially resulting is out=0A= >> of bounds accesses to the zone array.=0A= >>=0A= >> Fix this by adding one last smaller zone with a size equal to the=0A= >> remainder of the disk capacity divided by the zone size if the capacity= =0A= >> is not a multiple of the zone size. For such smaller last zone, the zone= =0A= >> capacity is also checked so that it does not exceed the smaller zone=0A= >> size.=0A= > =0A= >> --- a/drivers/block/null_blk_zoned.c=0A= >> +++ b/drivers/block/null_blk_zoned.c=0A= >> @@ -1,9 +1,9 @@=0A= >> // SPDX-License-Identifier: GPL-2.0=0A= >> #include =0A= >> +#include =0A= >> #include "null_blk.h"=0A= >> =0A= >> -/* zone_size in MBs to sectors. */=0A= >> -#define ZONE_SIZE_SHIFT 11=0A= >> +#define MB_TO_SECTS(mb) (((sector_t)mb * SZ_1M) >> SECTOR_SHIFT)=0A= > =0A= > This macro is quite dangerous. (mb) would help, but inline function=0A= > would be better.=0A= =0A= Indeed.=0A= =0A= > =0A= > =0A= >> + dev->nr_zones =3D dev_capacity_sects >> ilog2(dev->zone_size_sects);= =0A= >> + if (dev_capacity_sects & (dev->zone_size_sects - 1))=0A= >> + dev->nr_zones++;=0A= > =0A= > Is this same as nr_zones =3D DIV_ROUND_UP(dev_capacity_sects,=0A= > dev->zone_size_sects)? Would that be faster, more readable and robust=0A= > against weird dev->zone_size_sects sizes?=0A= =0A= Yes, we can change to this to be more readable.=0A= Will send a cleanup patch. Thanks !=0A= =0A= > =0A= > Best regards,=0A= > Pavel=0A= > =0A= =0A= =0A= -- =0A= Damien Le Moal=0A= Western Digital Research=0A=