Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3043536rwb; Mon, 5 Sep 2022 05:44:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR4gvyWsGNHAEHyQbzhQlkemaKikUdOZGcuA/h/aWvG2pCXfRyfeOON6318nELZAq37McOH3 X-Received: by 2002:a17:90b:46c4:b0:1fe:4d96:f6df with SMTP id jx4-20020a17090b46c400b001fe4d96f6dfmr19030482pjb.219.1662381880619; Mon, 05 Sep 2022 05:44:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1662381880; cv=pass; d=google.com; s=arc-20160816; b=WJGgFC2CEXD2+6nLs1WC4iLnVnvkGIPaWT1kZ8ukkdqFC27Kw9B/C1isN3Qfgg0i2o jaHNFKQEnA0dpzXbFTHM0m+X4OJaxsXYqzLLZ1Pqomiuz7k0y09bjOxGaLK0e4kQ9enI ebtdGESrywDxjGxmDCV6X/qjOMaLwbFneAfdPGeW7DdZsP1U57Je4WaMxGE1cyiDlZIp LoZS6Nz1eBGZHiz0S6CxE5w2vHD9BrvnR3K0Y+e/CgISsuqLe2cG3tITHHSq/d25rqtQ /C6NqmZCXhkCq5CPaj9k8hRPwqSDiFeUAs2p3lMayYfiTrd315wyomqV3AX6qym9u9ke Ucng== 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 :content-id:wdcipoutbound:content-language:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from:dkim-signature:dkim-signature; bh=JxItvLQcSBBE0d3TPpDiXwMF9PbXFuPIHtOpnDJrPLQ=; b=P8xjdm1wf+75GTUa5tDdOFL78ho+A2qOSgh2Iw/ffgWj6yoCIW55sEEe1GNqPGn5EE 23ZXblO7j7a2JspbHSGt5vYLKeycIARED0MQtoPeAY76S60NHj4uIvoghK1bftPUHaQo crF/bknvhBJABWo+ClBxemzx13YjF5TF67ZQT4+uCtnHiOSAZFSrjhBX8kIJeWsA38QP AMiViwYB0JlflOGoaP3VTa2UNpP0jK/p07L8oWMRN/ibM/rTf78M9chWHSlFEzybr0yj eztozO4Bq8FVhCVr/WE5dslaI4En0tBxe2Un7+2bo5GH50HFOIDov10kKqqcEnstmXCi E28A== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=YhNGkCCR; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector2-sharedspace-onmicrosoft-com header.b=LgMbXq5H; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a056a00199300b005369648b156si10697305pfl.276.2022.09.05.05.44.27; Mon, 05 Sep 2022 05:44:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=YhNGkCCR; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector2-sharedspace-onmicrosoft-com header.b=LgMbXq5H; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238317AbiIEMkf (ORCPT + 99 others); Mon, 5 Sep 2022 08:40:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238094AbiIEMkL (ORCPT ); Mon, 5 Sep 2022 08:40:11 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A613E61D92 for ; Mon, 5 Sep 2022 05:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1662381246; x=1693917246; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=dRqtirA4erdOC+9c/xhS7buZqzOkV+Yk3P8EL3H006c=; b=YhNGkCCRHmGe4wZZJDi0GDzXUdo62y7xiY2EoJ+V5uOZAajrwLDrqzYZ 2l1/JrC839lP7hX37LkFwkd2osyvqYjb01UCQpWjPQSBMDaqaR/71Ea+5 4pg3tKjdcIjRjEoebMjCyK5m4KjTaTv5z1rR9tPXwMfZQ7Y6KkfMWW2+i EphE2OB6i4gN5o0MXPLXfd/b62cgAlHXFE7dk53D+UJFyEFrATJ4IqbLP hSXrlAFztq4csQBmX0Qv2yspJi+bIcjcrsxgb3mvDuL/29vie7xyCBwQX 6sKs3JlGRY28FdFBtmEk3KB1mohcKX3i9Owwu4Nh1KPmIQ48VCEcInkHl A==; X-IronPort-AV: E=Sophos;i="5.93,291,1654531200"; d="scan'208";a="215695093" Received: from mail-dm6nam10lp2106.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.106]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2022 20:33:39 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CxmDA2CVPbeB7qjvwqACzpbrycdKRx+luQf6bBvfWSKf8lm+XQ354NawcmUQ3avBTW4QzxdEn11T9T8R/p9obCfo8L7MX2BPCmHKgsdXi3ViqewZ5LgA3jrdxxXyctI1jdIZ+7OONYLh3qoLAETziWP1ZSYUqvqLpZ/zHB4k+WAJ2i/wMIq/2lwrZsW4EWt+xZSulXbUPKJOrAoFEFBmR3HhIW9ls67PijjPrWQYzWtWkV2FBufw+q6Vlhfe5nJJWj/hKxCtvwAvWfTWjAoY0C7ek+il6EdrmjHv9ipl2NCvtYRqNv4Iirgt3br9GMUEhkpQyjideAoLsUvPfAulgw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JxItvLQcSBBE0d3TPpDiXwMF9PbXFuPIHtOpnDJrPLQ=; b=JmUd/dDU1wSNM6W9NVIrNTvNjrgZ0kmWEiU8BYxLPqTevsUVn+QyVGpemFjdJ6s7qBKW/MClgQE6RaEeCAzZntSXheIPCoxYBB8psmCE2nHrzhj7MTmMsFQkNrcdFxY7nyhVO5b2OuPoAhvasC0pAWWoUYwVTjfBd6AeE+HBF6A8MFpCfvx7NELU1xTtDUCAED8tAgSzW+oR1NZc1s39sQXa4StdGXgkynd7iNR0VG5N7nxnNDbQUpP8jUP6wE52Uf877vd9WLicsFHf7UAEBKQXX0T3fLYuxS93ogCB7p4jXHO0Pqpv5j5Y5uF5cWTBCE+6+zYVG7e2HarXYAf82Q== 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=JxItvLQcSBBE0d3TPpDiXwMF9PbXFuPIHtOpnDJrPLQ=; b=LgMbXq5H13fCXQsDineonA18x8jFAYQGuCxwAAdGblromTrEYm/VhC6jWf3F1ibTgK1tHKcD3QBSszuL7qYoXwJwLVhIKQrGYvNC/LWhReIJzW5BBvcCmqVs/rWaSx2GEosuQ5ZMg+r5lKnTBeCPVFzkiv0vcR6MCEz6Ap7A9X8= Received: from PH0PR04MB7158.namprd04.prod.outlook.com (2603:10b6:510:8::18) by SN6PR04MB4813.namprd04.prod.outlook.com (2603:10b6:805:a9::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.15; Mon, 5 Sep 2022 12:33:38 +0000 Received: from PH0PR04MB7158.namprd04.prod.outlook.com ([fe80::c839:6239:54ad:fc30]) by PH0PR04MB7158.namprd04.prod.outlook.com ([fe80::c839:6239:54ad:fc30%5]) with mapi id 15.20.5588.018; Mon, 5 Sep 2022 12:33:38 +0000 From: Niklas Cassel To: Dennis Maisenbacher CC: "linux-nvme@lists.infradead.org" , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] nvmet: fix mar and mor off-by-one errors Thread-Topic: [PATCH] nvmet: fix mar and mor off-by-one errors Thread-Index: AQHYwSJaL0sgHpgYm06eo7YO4ydfha3QxSsA Date: Mon, 5 Sep 2022 12:33:38 +0000 Message-ID: References: <20220905122116.2678206-1-Dennis.Maisenbacher@wdc.com> In-Reply-To: <20220905122116.2678206-1-Dennis.Maisenbacher@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e234198e-200c-49f5-9ddb-08da8f3adb8e x-ms-traffictypediagnostic: SN6PR04MB4813:EE_ wdcipoutbound: EOP-TRUE x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: yGFrEaMQLwu5GZkufpBq3JFOg6H+cHbbCGAEbfM9ZUcmVFHojSVuw+/5gY8xK3vYFWyMgGdEDPLcV1w2HcXWHIEWT/Vj0ZRbceKSr9/oPgwA3QzD4u6+0/8zFVoUzhwdVgitxOSfxNb8L5BQd/oqkk5DH68hDgabJz/PJoIZGzuSm2d/ZB2zlEHE7EjrihSktaYtu6kLHNxjspSGO7HwQNk5AIf0EJ1ciyBu0wWS/c9yomuatLiOESq8UZFYzr6Tan2uHgvvRz/F2ry0cIZp79TEGNyp7kZKEO2HyOp1VJp46uXm4bKlRvJv25/NKGbiE8pHyuBkYo66Ypubuy/RmBw5iMNYMZZtbUj9bsb6pcCv7wZP7GIVF0pde2nTexKjrSDf4WPHF4KWiR6fdjEnGhFTBuYrwNic86x2zH0HxYKbJsTHratFORTATQX2tBEdITSTGyeITyB1YkLCIGaNupIhXtdyXmLIJmnvv6uZHrfFBZvxZ0vOjLdTsle9ZV6zLfROA6RobsyQwk50rnOGUVhCrXDFT6zn/AJEXNeF5kMqCn/WrbcOuUG2SpY2Csw2ZlODZOefevWqIZ1V2elkzxqhazPAdQ7BmxiHiYYDnXgYh6S58e97rjTzTenwjBJzDj8eXN53TL35cyGD5T4hcFrkfsaCNQfjB1FhUN5hpGT/FbeEmSCVE+PF2Au6An/N5rN/+BW6LtIWXDIomR+BNVCNiltlV4FP0YKTnEOvRw3NUb5e99KY3wnxWZbCenjlBtitmcVVw9zPZOgWptito+5P3JTAaNsdD1qYNvk3Vt4= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR04MB7158.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(7916004)(4636009)(346002)(376002)(366004)(136003)(396003)(39860400002)(6862004)(26005)(6512007)(83380400001)(9686003)(8936002)(5660300002)(2906002)(71200400001)(86362001)(186003)(6506007)(478600001)(6486002)(316002)(38070700005)(82960400001)(122000001)(41300700001)(33716001)(6636002)(66556008)(38100700002)(54906003)(64756008)(8676002)(4326008)(66946007)(91956017)(66476007)(66446008)(76116006)(67856001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?GWlArK+wibxpi7x4J3OflDTia1cfq9uyblRRt0Kv0JoqIrLlsLkgqcsDBv06?= =?us-ascii?Q?F0rDHFKYyJ/hsPoFzyQeM4/vU8zUwFKNYRbctsX4430JyV//g00vUCOXfeHC?= =?us-ascii?Q?Fduc7VK5bttKtoJ/qnHxCR/6lnpvgc4yI+X2Nfe38z7ioAueaYkA9moZPZxT?= =?us-ascii?Q?E7k813Iy1n0CidwhPniUoncHpxknhy6rB7N9EzTVGRnio8TwjYpU+d5yigBd?= =?us-ascii?Q?TeF71nOpT5sXUQ+vv+vVS8RPHmMHyCRzzXjTu+7l21WZakdyGj91QSb2+K9I?= =?us-ascii?Q?46UiXwss92LrSaF5k6AVyAtbmAUzZo3/o/iO54cviHLsvMyTH3LUFLuQQ/2a?= =?us-ascii?Q?Fw/L/UWMHaMmb2cH/esN5PMiKip76F5wwS6Ol3XbYp8HdmawhLTbpYUSzEld?= =?us-ascii?Q?QTHAVryUMPLO6NQ0UtUilNgcSKeV+StNjQ5S/71tpZObAC9qbSL0IpF596k3?= =?us-ascii?Q?b/EMe8Qy/RSS8+c2S6qyRbAZ7MsOxUGeGKYWxRRDpJAjv6ihZszGDMRMk+hO?= =?us-ascii?Q?KQjltHE2hKKoRQLBjmvzZIQov8eauvCiK02trYFgDwpzug4mdyj5Oe9GV/D+?= =?us-ascii?Q?hZPqkH7HgBow+TbAmra23/35KMfCuRUM4BSbXQw+MylBvRA0YAY4E0x85Fl2?= =?us-ascii?Q?x/S15oydG7VxqonrIQWKeXOfmP9tADHki2+Kr0c5bTJj8+1vnmfV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rGIu3Z/kiPIXtuMWv9Oj4IKXJr0s9f8omQZLNR6z0Zp2t?= =?us-ascii?Q?9g=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: <4ABF074E98D5844AB2E78BEC724F9DBC@namprd04.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR04MB7158.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e234198e-200c-49f5-9ddb-08da8f3adb8e X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Sep 2022 12:33:38.0466 (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: qrnZET5e/hhnOtLUR0u0hCx+u+R/aL5O8FQaDK2U2z4WCbnpjGqwJ/K02yklAXXp8W8PUrK2vLQM+SE8K+PD9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR04MB4813 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 05, 2022 at 02:21:16PM +0200, Dennis Maisenbacher wrote: > From: Dennis Maisenbacher >=20 > Maximum Active Resources (MAR) and Maximum Open Resources (MOR) are 0's > based vales where a value of 0xffffffff indicates that there is no limit. >=20 > Cast the unsigned int values that are returned by bdev_max_open_zones and > bdev_max_active_zones into u32 vales which need to be decremented as the > returned values of the block layer helpers are not 0's based. > The cast to u32 is necessary because the size of unsigned int is > architecture dependent and a 0 reported by the block layer helpers > indicates no limit, thus it needs to be converted to 0xffffffff which > happens by underflowing the u32. >=20 > Suggested-by: Niklas Cassel > Signed-off-by: Dennis Maisenbacher > --- > drivers/nvme/target/zns.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c > index c7ef69f29fe4..606f21ee21bf 100644 > --- a/drivers/nvme/target/zns.c > +++ b/drivers/nvme/target/zns.c > @@ -100,6 +100,7 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_re= q *req) > struct nvme_id_ns_zns *id_zns; > u64 zsze; > u16 status; > + u32 mar, mor; > =20 > if (le32_to_cpu(req->cmd->identify.nsid) =3D=3D NVME_NSID_ALL) { > req->error_loc =3D offsetof(struct nvme_identify, nsid); > @@ -130,8 +131,10 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_r= eq *req) > zsze =3D (bdev_zone_sectors(req->ns->bdev) << 9) >> > req->ns->blksize_shift; > id_zns->lbafe[0].zsze =3D cpu_to_le64(zsze); > - id_zns->mor =3D cpu_to_le32(bdev_max_open_zones(req->ns->bdev)); > - id_zns->mar =3D cpu_to_le32(bdev_max_active_zones(req->ns->bdev)); > + mor =3D bdev_max_open_zones(req->ns->bdev); > + id_zns->mor =3D cpu_to_le32(--mor); > + mar =3D bdev_max_active_zones(req->ns->bdev); > + id_zns->mar =3D cpu_to_le32(--mar); > =20 > done: > status =3D nvmet_copy_to_sgl(req, 0, id_zns, sizeof(*id_zns)); > --=20 > 2.25.1 >=20 Reviewed-by: Niklas Cassel =