From patchwork Sun Jun 2 14:09:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13682867 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C08481E501; Sun, 2 Jun 2024 14:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717337529; cv=fail; b=Rnln46b7FzjoLQKz6Lf4AtrFVH7a/hKcpw1rdyt/0cLD4XBGxq1QW5cCWQPF4hVvcQbQBZ6Mjvi31KByfaZ83MmYRMglF4LlCmN3hJL3Qp+hqVWBVVb5Te2N3GAwresIpYlAdQlKccqAS5dMuuN948vZiez/yzgWbI7F0m4qZso= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717337529; c=relaxed/simple; bh=iki/1NYZ9YoGpsiuRdEgpVnO8uPeskpeOIqE392MusA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=UwBg7chmQZ94bXTdaWjbWhuHwo0JWc99K2GXRBN/1p3RHKX7B3VOXGlql8U4a/hiAOdRgZDAAKCvrqc+y0cSRKOrNtYVCVVtHk1L1Fe8MnUUuLwRvJ2uUm5O0K1zv9bF32fX70VreQRJ1iSkrRUFtRhW+m2SNnQAGHVuhBfWmkI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 4526h02i027447; Sun, 2 Jun 2024 14:09:56 GMT DKIM-Signature: =?utf-8?q?v=3D1=3B_a=3Drsa-sha256=3B_c=3Drelaxed/relaxed=3B_?= =?utf-8?q?d=3Doracle=2Ecom=3B_h=3Dcc=3Acontent-transfer-encoding=3Acontent-?= =?utf-8?q?type=3Adate=3Afrom=3Ain-reply-to=3Amessage-id=3Amime-version=3Are?= =?utf-8?q?ferences=3Asubject=3Ato=3B_s=3Dcorp-2023-11-20=3B_bh=3DIzYMElQdoa?= =?utf-8?q?fm/KOiCJoqkqo8DHg2mUS9JMz/MJ0HTqY=3D=3B_b=3Dg2iZR+YwuB3+lMC6gVdw7?= =?utf-8?q?mN96JrGDh7pr3jtH86kD8xe5gPaQ8etjrXaoquLmzSQOONA_jyBQLpsQIkDCID0xk?= =?utf-8?q?pBE9lolMkyjAa+6AQRxJ+IFxQg29M+L4EDDPTBzG9c/ghyhOrFG_/Jwur23sX8gMm?= =?utf-8?q?z7g4IpeH4KgphAnx6UCKMwvcsiviJhlBjRsx5XuL4+AGeYTBDlmxcqv_sHCzyRKAI?= =?utf-8?q?8gUC2ZOrBC1yyPpd1CjlsQKvR408JVXdShG5TPia12b54AfrX6c0YNekTVC_FBXqa?= =?utf-8?q?bSwbl3KhqKY2UZ7x8G6Sg3+bXchB5zTeV1fgqmLy6/HgGgSJbg3D1lJSe7RIQ4W_0?= =?utf-8?q?Q=3D=3D_?= Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yfuyu1cm3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 02 Jun 2024 14:09:56 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 452CPWHx003823; Sun, 2 Jun 2024 14:09:55 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3ygrquhb53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 02 Jun 2024 14:09:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FbOUvnktf7G36RymcpekUwQgST1bFiio7alGrMFOcTID+P+W1oyWGs1nbJdwlA8eXuqNCf2aGZo6WVy44Doi4kC67gQaOQyI3LKLs84PQXoSowJva5V42zxT1qIlHDSuEZugQaml5H7G1VLJ8a6O1m6qwSXjkDSIq0M/QKhkTR0NSLJEIE1VelCSCxXuz+NrkyIDXTwQt0/g9pxyRTWEXkp2kL3q6X+ZYFZUkbTHnU0pK0UfQlu9HdMWCP+9y5g+0EqAKgYNCQh8pSL2fD9/YAUVvgg9f+fkeL2U8MX7KP6TqauPLfOIqVB7ot0hgkgEyORQPRB2AGiEhw8ca5cCnQ== 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=IzYMElQdoafm/KOiCJoqkqo8DHg2mUS9JMz/MJ0HTqY=; b=jk1TtawiAwT/otFziZOEHetoS1Dtz1Mj/rSQutuCX5BbVcusSOTBHB9d+1xMDEseP4leMtbbMyTKoewRAfWv7w61BihyE1bPbMajf4OzYRs8vSmtl4wPtJvfhh4vRJZbwPCA84i2d3abNe5D2i9NosqtEF9isRdO6gEMdVo9GllwduMgd21pq+AgCDPi3dNToTmIQnWp2X9Yp4Gpl0tBDoEsq9ltSy5qkQUnPo/0KevKOqYKAx5dV7UFh+5iY4sk1zo38UHgTCnlVez5fwOdtGkIm7fmGlVzF3Bxb68qxSHAv/BpY6YxvmnaiAKNXnIf2SHrKfyzTfLUS6VWFsMgjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IzYMElQdoafm/KOiCJoqkqo8DHg2mUS9JMz/MJ0HTqY=; b=OmEhPEEAVxq5He0Q4lZfiXFQg+YIdqYhpjpoOrVA3uvEpL8g8H0Yj5RNcywBMQjajH+xi1XjmvTG5qXPRFXcZcw/JPM8JBIKG8kNPNwWApX48gIqdsP3xUhT+VW1gwUVCg3C2KvxVVVn1WSUSI33x8yT9G5rnGES/9RWB9/S5mo= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DS0PR10MB8078.namprd10.prod.outlook.com (2603:10b6:8:1fd::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.25; Sun, 2 Jun 2024 14:09:54 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%5]) with mapi id 15.20.7633.018; Sun, 2 Jun 2024 14:09:54 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, Alan Adamson , John Garry Subject: [PATCH v7 9/9] nvme: Atomic write support Date: Sun, 2 Jun 2024 14:09:12 +0000 Message-Id: <20240602140912.970947-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240602140912.970947-1-john.g.garry@oracle.com> References: <20240602140912.970947-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR03CA0014.namprd03.prod.outlook.com (2603:10b6:208:23a::19) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|DS0PR10MB8078:EE_ X-MS-Office365-Filtering-Correlation-Id: 28bb8fa2-7cc0-45f5-0ec8-08dc830dacec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|7416005|1800799015|376005|921011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?o4JQl3bGkSEYTIj6orPBRSmgYUz9tXy?= =?utf-8?q?03VSTQ96C5+wyX/5+stZmS0EcyVjQVeU6aBUOXj7I7LTszvjrdkkeJWXA5DhfgJub?= =?utf-8?q?2NB9xi6NcKO+WMeKpdPScakPVt/dU6lZOf3ZZQzfRPPCAr3zW0hlcLzESND/iwbWg?= =?utf-8?q?3cXpQT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8?q?vDqeKLfiMDThRvvLTbj8/JY8th1EreX+rId5fgsD4nuyc5USHAclyIDadEKYMuA8D?= =?utf-8?q?WW7jn8pw2NC3T2k5pqWP5GWjIFn6joa0FDRmtLOBnjsoy9YGGTguhUCkcvg2f0t1N?= =?utf-8?q?w8ZVuH4IpWNVAfqES+SelmlUliiWMSyjtdtHpioCdjqNIKZ0l4E0m+VmF2af+MKu7?= =?utf-8?q?reGpcN+LhGR71BotLlpQkAYoUP9p0ex6lzYifaLbJRIVh658g/EhX5Q26CZk/sc22?= =?utf-8?q?D7ewhitV47O9/?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(7416005)(1800799015)(376005)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?tCce6qGF8KB1U+tD9esGvGBKVexn?= =?utf-8?q?7C0gU+h4kbw6mxQidKo5cb1rMxp00bxHq4hetKw/fZDQEWe+ocn17nzcpftVxvL7w?= =?utf-8?q?dkXvJsHBywfq+J1Kg1qQNXJ5MsOlYJeBlpuOt6dWr9YqDatGYJU99l7eBDeSF4C6q?= =?utf-8?q?BkcO/2zbwREy8gksvTwdhapD5EC7oFJdZHdpdPaV5M3vir1eQDVr9FWBsAXx40BgJ?= =?utf-8?q?HIf00TCrHvcQLop0e/3WuvxScIHrtTYryweQErjWMCQlU7j81IHxc367d2oTiCGrL?= =?utf-8?q?1oV5YWjJLGmMZDI3WCDhJuUR0SvXA9PYwqpyA4amPh3zxKwKJzVwPtzxU4A46s/dH?= =?utf-8?q?4eXozbmnJym2hb9G4hVRTnzT3NRGcS2eO2yq2cDFWrZaqSd9kaL+e5z62STToCnRi?= =?utf-8?q?KOx7fWvUhm4YeQMOyG3bYh0cd3XnNU2VR1WessF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SxdDJik00PnCwXE5Xwo5snLk2ab1+TCDxc4xWTqbNv3?= =?utf-8?q?OLCJFQhQfbgZQwt8WT2O3687DtS00e/qNXcjR9ORWvenpHyP/v/nQiAUtAzQAKuUj?= =?utf-8?q?XRsU292nZOAbrjPcKNOYj4xrkl9uCJAtHxzdqkav844muo49LeNnzcKb8FNH3NKzd?= =?utf-8?q?QohvGZomJXi3CWChey+dWaABCltWxXSA6o0+GQTrA8ONvW1Y18PMGYOtjSGTnNKl/?= =?utf-8?q?t+EzXTbSPVNX1gGMAASPCkSDM2+mzxx1sg=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: x3MUx3tISAv8l5+iePx285wQnWl5oZGNY5usGGCzvVjFm+TnFxDmWD4sslg5WBWGV2xt91K1I3kGtt2ro1Owb+LfOREKtsgofD1UxYNt96FlWL7gi8yy09Ceffyj/IIqiInBbuMQmKU3o3kNlkg/osSQVZqwyZvbS07s/pv7715zj7JZbhMjIEl0peH6ByUNySTy+StLsA75XeOc/V+D26FpdHNOAJ2eYqH0vCv0UIBrv+QkeuXM6gjPofayrr+W8tbzgNFESkphliZ/4sJysd2Mk3eTQoYimdYwcUUa4IINmjTIHuIbF7dYY9HzE65T4seeawdJKAs9cbLmOpKZstGUZoqqJzdjS7S4EZ61QlnXZ0vtIap+te1Nh/jSrHc4BWN6umz7HwCY3/MQzWn8A4LqeowMVJlKLK7EGhuEyM3QQRo/MnQOS/EO6qjHH3ywsKicEmYOndGHMCPMYjt+lRLJKi9ioEgu2U2T76/YR0kI9yTYKjKvqx6sTvsA2MlB0hDhFp2asLN/YP9y8qMzEJSxH2CMwTa+Lq1nVdIM32CVzEqTc31HQR/bxdAEg/ybPhdJ942SVTLWcjr8Ly1qqH/Rr73d/LxDcKNLeYDpX9I= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28bb8fa2-7cc0-45f5-0ec8-08dc830dacec X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2024 14:09:53.9974 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sY8NSjkF2Qo2ntBgspVJEXqJ8kwdPGb4LNkgBHi9mL+2TJW4b4KQ2vm6bD+gYry3JAfHZVJpnXXsPkUWwsxiRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB8078 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-06-02_08,2024-05-30_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406020122 X-Proofpoint-GUID: 87tPnG2vNzXvKEi1UDE8LyV5AhLh4oIS X-Proofpoint-ORIG-GUID: 87tPnG2vNzXvKEi1UDE8LyV5AhLh4oIS From: Alan Adamson Add support to set block layer request_queue atomic write limits. The limits will be derived from either the namespace or controller atomic parameters. NVMe atomic-related parameters are grouped into "normal" and "power-fail" (or PF) class of parameter. For atomic write support, only PF parameters are of interest. The "normal" parameters are concerned with racing reads and writes (which also applies to PF). See NVM Command Set Specification Revision 1.0d section 2.1.4 for reference. Whether to use per namespace or controller atomic parameters is decided by NSFEAT bit 1 - see Figure 97: Identify – Identify Namespace Data Structure, NVM Command Set. NVMe namespaces may define an atomic boundary, whereby no atomic guarantees are provided for a write which straddles this per-lba space boundary. The block layer merging policy is such that no merges may occur in which the resultant request would straddle such a boundary. Unlike SCSI, NVMe specifies no granularity or alignment rules, apart from atomic boundary rule. In addition, again unlike SCSI, there is no dedicated atomic write command - a write which adheres to the atomic size limit and boundary is implicitly atomic. If NSFEAT bit 1 is set, the following parameters are of interest: - NAWUPF (Namespace Atomic Write Unit Power Fail) - NABSPF (Namespace Atomic Boundary Size Power Fail) - NABO (Namespace Atomic Boundary Offset) and we set request_queue limits as follows: - atomic_write_unit_max = rounddown_pow_of_two(NAWUPF) - atomic_write_max_bytes = NAWUPF - atomic_write_boundary = NABSPF If in the unlikely scenario that NABO is non-zero, then atomic writes will not be supported at all as dealing with this adds extra complexity. This policy may change in future. In all cases, atomic_write_unit_min is set to the logical block size. If NSFEAT bit 1 is unset, the following parameter is of interest: - AWUPF (Atomic Write Unit Power Fail) and we set request_queue limits as follows: - atomic_write_unit_max = rounddown_pow_of_two(AWUPF) - atomic_write_max_bytes = AWUPF - atomic_write_boundary = 0 A new function, nvme_valid_atomic_write(), is also called from submission path to verify that a request has been submitted to the driver will actually be executed atomically. As mentioned, there is no dedicated NVMe atomic write command (which may error for a command which exceeds the controller atomic write limits). Note on NABSPF: There seems to be some vagueness in the spec as to whether NABSPF applies for NSFEAT bit 1 being unset. Figure 97 does not explicitly mention NABSPF and how it is affected by bit 1. However Figure 4 does tell to check Figure 97 for info about per-namespace parameters, which NABSPF is, so it is implied. However currently nvme_update_disk_info() does check namespace parameter NABO regardless of this bit. Signed-off-by: Alan Adamson Reviewed-by: Keith Busch jpg: total rewrite Signed-off-by: John Garry --- drivers/nvme/host/core.c | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index f5d150c62955..91001892f60b 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -927,6 +927,30 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns, return BLK_STS_OK; } +static bool nvme_valid_atomic_write(struct request *req) +{ + struct request_queue *q = req->q; + u32 boundary_bytes = queue_atomic_write_boundary_bytes(q); + + if (blk_rq_bytes(req) > queue_atomic_write_unit_max_bytes(q)) + return false; + + if (boundary_bytes) { + u64 mask = boundary_bytes - 1, imask = ~mask; + u64 start = blk_rq_pos(req) << SECTOR_SHIFT; + u64 end = start + blk_rq_bytes(req) - 1; + + /* If greater then must be crossing a boundary */ + if (blk_rq_bytes(req) > boundary_bytes) + return false; + + if ((start & imask) != (end & imask)) + return false; + } + + return true; +} + static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, struct request *req, struct nvme_command *cmnd, enum nvme_opcode op) @@ -941,6 +965,12 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, if (req->cmd_flags & REQ_RAHEAD) dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH; + /* + * Ensure that nothing has been sent which cannot be executed + * atomically. + */ + if (req->cmd_flags & REQ_ATOMIC && !nvme_valid_atomic_write(req)) + return BLK_STS_INVAL; cmnd->rw.opcode = op; cmnd->rw.flags = 0; @@ -1921,6 +1951,23 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl, } } + +static void nvme_update_atomic_write_disk_info(struct nvme_ns *ns, + struct nvme_id_ns *id, struct queue_limits *lim, + u32 bs, u32 atomic_bs) +{ + unsigned int boundary = 0; + + if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) { + if (le16_to_cpu(id->nabspf)) + boundary = (le16_to_cpu(id->nabspf) + 1) * bs; + } + lim->atomic_write_hw_max = atomic_bs; + lim->atomic_write_hw_boundary = boundary; + lim->atomic_write_hw_unit_min = bs; + lim->atomic_write_hw_unit_max = rounddown_pow_of_two(atomic_bs); +} + static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl) { return ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> SECTOR_SHIFT) + 1; @@ -1967,6 +2014,8 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; else atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; + + nvme_update_atomic_write_disk_info(ns, id, lim, bs, atomic_bs); } if (id->nsfeat & NVME_NS_FEAT_IO_OPT) {