From patchwork Thu Jun 20 12:53:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705368 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 AE83C1ACE73; Thu, 20 Jun 2024 12:55:01 +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=1718888103; cv=fail; b=inV8NH26BePARCsUN9B9ggxtO/QSy7b7go+HnVgUP8p1AB390RvPPF4tk6WNtwx/vATXZfLXwAPohuSPAoE8LS1IFj4Cbu7JchDawMQGjuvwZooMItG1FoIOCt7yJiW/7oubBaaxL3euqZCBMzapjptphax04U9S1S20HFCPfvU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888103; c=relaxed/simple; bh=I1Vy8K2ut23Smi9sHmbkjQ3l8Nmr3J+MIkqdSXduYO0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=RMhluQR2uCUQKCzWKuXJavJRrWd0ZE6wnH6g/d8dhSS1a8h3vhzX7w9sjrAdlyK3OIGaTDNmpSbihuygc77cDGrbE9FlwB6mQjfQjnTEGi10TYMB1oSSX1YsQhq114hISH19m0+55zoDgLMIMewMMmmLA8Qxhb2jr6Zt9Lsg+6U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=H7zuEBTs; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=Wx2z1Vhb; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="H7zuEBTs"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="Wx2z1Vhb" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FEXO014356; Thu, 20 Jun 2024 12:54:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=v9656SdQpzrKVNwFfsUbO8Jc9qLT9UDvLRy4cJcRfuw=; b= H7zuEBTsLUpPhOuZ8KV/rw5CxE9ZWkEhhY9d/4R5ceOuQZrrMsrfhodqZTjgbIJL o0zsT/ZP8oG9SXyaoqn1ektsiKH+0eZAGlNil6AbMyp3URq84YQtCW+oqztPr7Mc P8GHMKMAM1Amk1qYBU0RBU5iRkr3SpiniUpdrpZKTosm8MJUoHrhH+QEurlhv/v8 N8yJ3AIj0hORSI5d99pqrbomcLue7M4TliTCaYJUuLbjhKFVeD6PNkSvoq5W2lf6 ekub8nXQ0EgOi3qJzUbBvImdVWBYpkE1tpV2+FAzpsmdT5oZR+gXxTii4Lw6PZGp E/a5Mo2Awc5aHOsqM9+f+w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9gk53d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:28 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KC7utY032824; Thu, 20 Jun 2024 12:54:27 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dae6dx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G2CEiT79VCRMexP5o6oNY6IcfaLoga2gAlFK206lRIvQxnsRiO9C3nUYpRlYxuPn5TjEI1DlKnGyarrP+ygtiGhFq6GHezUCKcLuzrJV8HImSE55nglLYdiklfD4gW/IN74CdEddjX58guhS8/xD7i0QQsPC4zcRVEHBsW2Gw33HpjC7OELxUIGB/o4Y/KIMR8/x0o39Sq8ugd2o1VuZplWH1x2/gYZTOlhzB/h2ZtOKFdPd4ljoX/CEXzuDHmeTmVOVZYa87I0sCP78/0TN5JenLzaLUcnkyb21z7f9JfFGe8Wxydn83qeShjytg6c/xmnZnud2F2cXiCM+qwrh5w== 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=v9656SdQpzrKVNwFfsUbO8Jc9qLT9UDvLRy4cJcRfuw=; b=Ycd5E24fhxUP3O8iRCcsaA3Tq6ePq0T44HYD9owiuH8H0EJV6/ivXUeNM/+kuBfZZ73rqZwoBwXyvCQCtBo4+w/bLNfF1nFR5CMVrBC+CA33EeuMkqBuTHpH8dfS/BNFeM7GOZTSug50OsPrN9tgBt0nHrbfIqX5GUuNVtx+OocpHaOqtPioyuuKx/bBMSHKpOxust/Hu9QSy3FpRLzyF5nZmjAlHLoVq3uonP10WZvTAtB+Q1zG7IvJp1f+70BjDXAZ7uPng073WrzJSIFnEvlX3CBTeSrrXbcwpWejGyGFVxEiNzso5csv4GHCYXgA76BV6O5o0Q2297hEdbBpnA== 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=v9656SdQpzrKVNwFfsUbO8Jc9qLT9UDvLRy4cJcRfuw=; b=Wx2z1VhbPQLOIHDQyTRNfCYp0TI86IcPepVhD0xT5C8Eiq1DRkiACNtWgOFOZlMwTyWE1h9DMWPWfbQnsyK98+Je8dTn6EaUa51QgYBWnQsP0EUBQIdRdjpM8e6TZ28Omrv4CuKjJfB5vuV3bVEZ64iBsNr5DGJbjP9+fVpHnqU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:26 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:26 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, John Garry , Luis Chamberlain Subject: [Patch v9 01/10] block: Pass blk_queue_get_max_sectors() a request pointer Date: Thu, 20 Jun 2024 12:53:50 +0000 Message-Id: <20240620125359.2684798-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL0PR02CA0020.namprd02.prod.outlook.com (2603:10b6:207:3c::33) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: 93237373-85fd-4e69-69fb-08dc91281d79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: /wcUJgjYsiSDN1SBME47XgSUaP6s9nQBMcTHTfXI3fgp4b3VCkvRINpmw5wPXp6pI1cVB3ejoaWnEXy0SOWcALsVbH0M4owEFk9uVNR+hHlP7KHtXa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NejCVPTSDyf5OEepVEaP8lpuDnfD2pnxgkj9m8eFIVy1tjeTuGakWstfjBYko+21IaRB4/FoCp8k3Km0f/sCbZDZsmksr4M58i4NIn+pTWU0GoWxSH9GTzip87rpP0mFF06BjmrtQr/p2IaL7xo/sysC4mB+OWSmcCKVBxGLCzU4QoRs1ZE3tYfYu6x2LjY= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9GJKSagrhPf3gGAkcR6qN6axgnxCvIkF431FoH9ohcJLHcaRFOkpjfZkAsyb5k6a1DwpFOuMxLrPqox/yB9DHLdIHBRCVL8E/Ty1pJQlDTUgrZQkYhMe1ETkKiu3I5udD8SkKz7QSG12PEwWyXcKVIAoc6HyVZhSrmIWQe7OmCCZK8mzlBBBL+RKLbgbhmZGsP8LnR1sWW/6BLgGVyEWzMr9GKLZA2AsE2kF3clnXOsV9LRviScwJitrOGppeF3B5T0JpDXO2ikaSZw4Vxh5x7PzMcUrqIRoVsxiukyNdpkaONYDt1DPrtHzNs5TgLxPQekrJVUPn3kw8gW90Ek89suPnEuJM1LGSy7UR9O5RGTAfiILBhLXeWBGjhZXpf4Zmk0ou7aoimTYyM3bOH/KpgQp+Mtm8QYuhE+Ybl1TnSg/CzZk0ZhstyUF4t1Pw+iwldsOYr46+tk96e3hFiMfFqigWxnx2WVxwfy829606iyCGlMcm/IAQ7bqTv1qFflsjX5tSuYS+CdgBmjZ/YPv2LqivKlJFCnmJ/Z5NF8iiGhNHOACaa+qBkf3HAcjnYhpEQXzXCGIUc8eUr3wdrK8wJYoLXe0nIRLss4e2/6sa8PQzu3vaDx9mAPZ6GXIWAWRkTC8bO9lJqd8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d/AzWyETExM0VRMR5DP/9z0aaXu72ULTokCkNwJvaevvQ8+JUPRm9iNaY55sgBrGRQA9l6sug6+tXddcS24T91Q7UP0AWA40hT/wJmkj7WJPUSOZD0lpmtuf0pOUCwJgs3zAKkCRAb8AXh1uT9ndZoK3bSTqBU7D/BtxpuVLo4+H1pb7Vo3DY7p5Fbtyp9SUrJThkHmDtOZUTIYVLj7Wwj8eow0YU/dsVpjwVa2H+VXhq2B8qRa1F26AwEacC0J4wSzFH/8vUJdnTFlO/AOxvkYE7WP5PCc3LtxU7o2Md+c3DQldXFYvKDE8o8ynynGhpfOEoHIwwzLnECwDyJ4VzKVQioOGHpuQyl3Xu8l3v1OJ4JmFZ1bpI7iQySx2p74CNtcnTC+JORYHd0NSo0Li+KBSobKHJP7VKmthYn1/IMDynyhH+SJQW1lJxo/rVrnhgAL9VelyvCaTBVE2/m/gG8dZO51pXztUVKunhohzWRyH9BmVrybWztn5VifJBAPbb1g6Z5p4kZDgI/Ou0vmMhEIdGfYWkzFhMSf+X7+e5AFqfmfgNxT8urVeqRGBn4DtQ3rOvaL6skEzySVspRXTQI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 93237373-85fd-4e69-69fb-08dc91281d79 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:26.0117 (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: IJqagTFZnCLYbhivnPLHpeIzkEBpSl0Dpy0OB8avldEQ51AevJEtlMsGdMT0HJUn2CL7O5VQCQ6xRxkFsD8Jhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-GUID: -DXiYAKlmtymKDzy0Ay79f4PqhHc6PHZ X-Proofpoint-ORIG-GUID: -DXiYAKlmtymKDzy0Ay79f4PqhHc6PHZ Currently blk_queue_get_max_sectors() is passed a enum req_op. In future the value returned from blk_queue_get_max_sectors() may depend on certain request flags, so pass a request pointer. Reviewed-by: Christoph Hellwig Reviewed-by: Keith Busch Reviewed-by: Luis Chamberlain Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Hannes Reinecke --- block/blk-merge.c | 3 ++- block/blk-mq.c | 2 +- block/blk.h | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 8534c35e0497..8957e08e020c 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -593,7 +593,8 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq, if (blk_rq_is_passthrough(rq)) return q->limits.max_hw_sectors; - max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); + max_sectors = blk_queue_get_max_sectors(rq); + if (!q->limits.chunk_sectors || req_op(rq) == REQ_OP_DISCARD || req_op(rq) == REQ_OP_SECURE_ERASE) diff --git a/block/blk-mq.c b/block/blk-mq.c index e2b9710ddc5a..47fe9d19b8f1 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3036,7 +3036,7 @@ void blk_mq_submit_bio(struct bio *bio) blk_status_t blk_insert_cloned_request(struct request *rq) { struct request_queue *q = rq->q; - unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); + unsigned int max_sectors = blk_queue_get_max_sectors(rq); unsigned int max_segments = blk_rq_get_max_segments(rq); blk_status_t ret; diff --git a/block/blk.h b/block/blk.h index fa32f7fad5d7..20c5718815e2 100644 --- a/block/blk.h +++ b/block/blk.h @@ -182,9 +182,11 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq) return queue_max_segments(rq->q); } -static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, - enum req_op op) +static inline unsigned int blk_queue_get_max_sectors(struct request *rq) { + struct request_queue *q = rq->q; + enum req_op op = req_op(rq); + if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) return min(q->limits.max_discard_sectors, UINT_MAX >> SECTOR_SHIFT); From patchwork Thu Jun 20 12:53:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705369 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 359FD1ACE9B; Thu, 20 Jun 2024 12:55:00 +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=1718888103; cv=fail; b=CLPmAPVBt+BRWCkgUy0GDvD/GcwhovEA6RNPNcGvpmP1mM8+QJXE0trOxU2YKMF+jASZhpIuKsgEsQFgM3x1a+s3Oq/lMeJjRwNfH+9EE1zNQ1WMb49VBFZ4ZCr50nEeivKgLRRIL2FRgaiH6KHUxGONYOczgI5pizz0hmDagxI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888103; c=relaxed/simple; bh=60dMqvzOApVi5JKuVDRuSxfef4xdEAXizRRSE3oooZs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=bkx+MN+UIzQmLJeQdDc61mbfEHTlXWhr0HEsDsmIiI5qWE9qThNOJEz/hAM2uqk7jiuLqy9cGcvF4WQRLTai5s/BZAC9m+u3r3NP+PB3oXNZjShytzsHlof4dJoLBfE13g/rKiqvf4nAf7tpH+Fhz/sJfZKc7frsfqrvGz1gbFk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=CAXxfhPj; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=M/dq4gTM; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="CAXxfhPj"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="M/dq4gTM" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FGqf004954; Thu, 20 Jun 2024 12:54:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=AIIb9rF3V3HBQIgW17CjTt0sui879UkFkIeDM++OUNY=; b= CAXxfhPjm4vnwr/h0cmQAQACnhwPJhhSEb6+ojEwHu+4Qt8tT0cazyuunMhKCNgo WgfoZJSSforWI+QSVxYKKaVvHaTNmLNFEvpNBaqLXquMbTAULce4PhLdwpMRJNe/ tRylMWlLk8YWOjOwNHAzOZp3Kks81M7JbKroHwwPp5gsy7f2F0AWz/r5ufqNScij 1XrAjMtPFj5GAxmxBjT2ZH0kkoor6+B84BkXLIdmbtHqnzRdgSXr9N9cMHE9DUms EBs2716slIp+HzOLB97MStnonPJ4FRP88+N6G/t3YFpUUp6cgZEVribdxsDGy1OW 7UWpw3buOT+YCu/ifhuCYA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9ju2uq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:31 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KCUOi2034795; Thu, 20 Jun 2024 12:54:30 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dap437-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lwm5teYBOd1fKhN5Jz5Vel77PZFiUVdt9I7Po+SKEZexYRedsXgaZ5QuCF9zItbratT+xCQnieCJqm2OA/2KRmqUQEdQanKeT6oiB9kbr52gbDwBJyebTY/duHsnfsOdFInrGOkSyW8K30OEX5ruTJ7fhjLLlYu83/y12hyOh93jX2fxW/P+YP4YhK9aWA00Ggr81vCV6rG7bmcD9YxDiiVhFLlDpHfmvYQHvb4vLdq+RSy1Afw6HooCY/cLqcZcYk4EJAt1sZDcasKi48AFN5Z0u9eKmYGCLFrp9oImq5g+08GJ+Mhas8y2549sec5ItPaJbKhcFRvmSvC7rPUEFw== 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=AIIb9rF3V3HBQIgW17CjTt0sui879UkFkIeDM++OUNY=; b=AzSfoBORjiQ1XEsdJDoEgikVNkY1FRDyW/p69J12iZVsSlUdktHHqmGhpojfOWcxGWFI6ELSjrglKuhu+Sn/bNu1MZj/RpucgfN1BN3KRJ0tHDflhIxt1aRNGC3MhDfYLtKWe4dNvTt4AnmVjYViMd04FcjrxtShUVFLIEXhfAfigv65kmqU34BEXkgM59PmFa4jo9Q3ne+lEstmEN/zhRC00jPDj5rK1hEuUmB9at3HbmuPQFAVrL24KKrHdWulB0vyuZwPKt4wLN8PGmKMOmZsOwnssOugpNx0KHaPFckOVWpse1qSyjBAJPfH4OPZu6Yu/eOoQGYqDEixEmv6iQ== 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=AIIb9rF3V3HBQIgW17CjTt0sui879UkFkIeDM++OUNY=; b=M/dq4gTMQ3FWYsIB8MIkUFvVeO2P8vLVdNHK+VrmgJSP6d6Fd1KD/4L46f0U+ALIJkj19KXgPmduzyVXm0xVW3OPdKT+PbFl4PrJGyyKvd41HQAsphaMvpJNJetRMEaiJXCFthoCpw/lc+D12GoHu1wH12HbpRohbqI9VRqJ6rI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:27 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:27 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, John Garry Subject: [Patch v9 02/10] block: Generalize chunk_sectors support as boundary support Date: Thu, 20 Jun 2024 12:53:51 +0000 Message-Id: <20240620125359.2684798-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0358.namprd13.prod.outlook.com (2603:10b6:208:2c6::33) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: 1fe2fde9-54fa-4266-0951-08dc91281e58 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: 2gsIRBzyUQg82MC5Z1nw7CfqO8YLCZs9qUQGQkd/tkTb12mFW07x7JOWJ8DLOD0A7Enx5k2flft/KwpMeM5Rj2a4dEHDivXiu77KoUA6/9/o3tIetg4EPHp8MPs42dUY3fI0ov6q526zTAYYTF6zMsMP/TEWSY85YR6+ZNjpjj48Z5rflenDGLZ8bGEiGXDAHJ2ZejXm1Rjf1mmV0v5LXZsiJEwllTcd2ZDyzfw2l6QaAIUhdcUmxj9n9jczIBcp8MNB4TuGh+UkCzMb8OPwWc9ZBTBCc6E1gIZLT6eqcx2jnnzBh6U0QAsQqzossE9etW/9UyO/Pl0pmvF253Vlskp6o2bJ0VGh1dIXRbqBUsrUwwqujJfiQn520m2nZ0zDV0Fg47jSHr+izwJvDR99h5285++fNCS0z+4Cq3WsCWEcurxEkPjdt/PRIJjXJTSzARo2qty3mbbcjSsbGuGwDyvtJbsuIcjVcLI3JFXwJ2VldgtywZ9yCOiSPc+lYPaT8YeZue3DDyNPv9zH9HmnNDFRT6IFtCQcYw5TSybVFCqC55A/PcmGy4GJU2jKwowvJeNxr6b4NgLhiCvJTY7fl0cYouwftVwxz2icziWExhv57XL78iSX6CwLLrspkVX4W3rjEiPIMl6QAZmXJaOwHGh119OmBdmaJnH6/HAhi7jgCPThRGS3CAFk5dV2p4H177V+rCvNVKUGxHsUhzdamBZWc2ygDmd27+IVE/9ZQEx1s0iTLG4mpGvYea+Cc/EOHesMPYD6ivw2MWsDyp8ceuk7tV+C3QO4qqggDqVqaGsPS2l2oo2wAwQZV1D+WoP00fFNTBTxJq475U62FXQJq9KjeoC3rfhsH7XrUeKUcX09y8D0TzbUXTO8+b219vh/9a5RHS9Ct4XTHLE3Nv1Ypmv8Lreti7bDeB2uRYNVcj9xNHLg+hcur/bbeR6gkUytWKXSF90SJRbEETROJOWP9gEN2dqJgzWnKY8jVbAzrFnxTk4dozrdrpP0FXKmNUl7Hrm3vJBUibt9gFVmJgXAKdP5gCFheRzAJnk/kw7vZG/hm/dr/0R98hqFhRSchgs8OORvU5NRXSRHw+VxD4LEYn7lN+fDbLJyWTSyD04p3FHrtkcJ6wpwTDyo09nY3lgBf6P3AC+W9PvRkAFQskOXQ82bQNuOL9btPXpxjairE2vhCoAjDQ0MAmYGQzBswjxfu9bgXX8od/2w9/IfAohruZtsHAacRsYcKheL7ppt5xr83JO/e+UQJ0Z9PayftEKnC50dVtwEFT36bfZQQ+WX+v4b1DPXQneGnykLeODFeGv0qGGQoEoZLqEhmZTUdTSHjq/qbmaGI9BDoAHBS2vTMr1JHMEzjW/uG5RJ4Hji9eA= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uC1Br6xu9kUNJBmSYBW1DyicCUUYGVxLwWBUMug8uebW1Kzp0R87yxKTmBiO7OnQGMak8QfGwsHddfjXJo9e1Thb7IdeHZS0yTliMSdUj3wjiJNKkSxTq+GDXerus00BSwl8ShZ38NgwbIgHaL+mllzv+2eoLKJSrkiFqoHgT3zxfVghVdMsNl6Z2gb0lKuMNQOpaO8VGtSaO0yXCBe3uqByc4KnBmUsYuiNhny4Nn4o61ysB1lo842rVIyNYZRGrPaPBI58tjqIPgQWtYJzXS7UEzx6ujjFOpJ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0RDoHH1TnKG2qVDpqw6VLAjgms88RJCvsbZofupDkMxrA3eSVTXGg6kP6b1ZsIDCehOnLs+A5W/yTtulbudGTrkiRitexYvklZNX/TxJ4pMjIpMmyO1LF5NUPvgALVblKh4I+bjyEfxYpByxeUwNPcozIlsKtQStNPftV4Kh4B2hoiGntugOzIKC4N+AjpjmLERJd+OHrh/FHD9edl1nAiuzLsYOcysxLWy/ERTP2VYSU8PVUW43XPwOYRA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: IKX9CnVmQ84A/9eZ591uoc6qOUgm6X07I51C8Zpe2/W8f3EJOZCPe2eeiV29RhP9m9z8kPj7lHCYTAxsxRsaZZV5R0fkO4vOXq5vzgRiBN1aVb5PLd5yXC4RFA4xTUMb/KILh+dx1/8LPmwsZ486E7JbNcfdPqQXhgNtl4UTR0QEAJgtFg11elhlASdmDW7DdBRdMTo5TW4d3mQDhEeyP2Va6Aw+5ZXJgxcr+w23qFoPVWy41D5vqdDA/cymdPOHUKMGcZZUHG8SDJFwKRB5Rmae5Tfs9Sh1whBl3kE3rU0bg4GJF6TNeTmssBGzgkSOvuKOGaq+K4k4zpZgWz0WfB2118yyD2LWlSBEpFcxS92ntJDnUQzqjO4l3fE+G81gY2X+jCONxCnjpIsI6tAV+ZCHOyqjL/WQkfp1LK2Bp4aFAuPjkMMcF5n2IDaKIn5SpSOhL3VJx7qI5yTYcV15jufc/aEV1ulFryzZ/bHknMJnmhSHMFALO5SgXHtYHCDYveA/eSKkXLzO2Aw4MVww3bbB2+n5DiKyGI0D862gPdMuuVwsZAgJNdbq6yQDe0y++MF4lVd8/e7BCXO0sMbLMpQfx3EEUqb5qTthiAvFguI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fe2fde9-54fa-4266-0951-08dc91281e58 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:27.4774 (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: RJqOB4xOWt96bXMB+HCXDUdRRwEytd91Bpz6m72O8hu+MnV4kjLxiBGswzqU1oGllWowtL+P6o/GmJNEwvqX4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-ORIG-GUID: -XYMrkC1BRon8-FyDOv5enwcIGA0Anxh X-Proofpoint-GUID: -XYMrkC1BRon8-FyDOv5enwcIGA0Anxh The purpose of the chunk_sectors limit is to ensure that a mergeble request fits within the boundary of the chunck_sector value. Such a feature will be useful for other request_queue boundary limits, so generalize the chunk_sectors merge code. This idea was proposed by Hannes Reinecke. Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Hannes Reinecke --- block/blk-merge.c | 20 ++++++++++++++------ drivers/md/dm.c | 2 +- include/linux/blkdev.h | 13 +++++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 8957e08e020c..68969e27c831 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -154,6 +154,11 @@ static struct bio *bio_split_write_zeroes(struct bio *bio, return bio_split(bio, lim->max_write_zeroes_sectors, GFP_NOIO, bs); } +static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim) +{ + return lim->chunk_sectors; +} + /* * Return the maximum number of sectors from the start of a bio that may be * submitted as a single request to a block device. If enough sectors remain, @@ -167,12 +172,13 @@ static inline unsigned get_max_io_size(struct bio *bio, { unsigned pbs = lim->physical_block_size >> SECTOR_SHIFT; unsigned lbs = lim->logical_block_size >> SECTOR_SHIFT; + unsigned boundary_sectors = blk_boundary_sectors(lim); unsigned max_sectors = lim->max_sectors, start, end; - if (lim->chunk_sectors) { + if (boundary_sectors) { max_sectors = min(max_sectors, - blk_chunk_sectors_left(bio->bi_iter.bi_sector, - lim->chunk_sectors)); + blk_boundary_sectors_left(bio->bi_iter.bi_sector, + boundary_sectors)); } start = bio->bi_iter.bi_sector & (pbs - 1); @@ -588,19 +594,21 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq, sector_t offset) { struct request_queue *q = rq->q; - unsigned int max_sectors; + struct queue_limits *lim = &q->limits; + unsigned int max_sectors, boundary_sectors; if (blk_rq_is_passthrough(rq)) return q->limits.max_hw_sectors; + boundary_sectors = blk_boundary_sectors(lim); max_sectors = blk_queue_get_max_sectors(rq); - if (!q->limits.chunk_sectors || + if (!boundary_sectors || req_op(rq) == REQ_OP_DISCARD || req_op(rq) == REQ_OP_SECURE_ERASE) return max_sectors; return min(max_sectors, - blk_chunk_sectors_left(offset, q->limits.chunk_sectors)); + blk_boundary_sectors_left(offset, boundary_sectors)); } static inline int ll_new_hw_segment(struct request *req, struct bio *bio, diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 8a976cee448b..7d107ae06e1a 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1188,7 +1188,7 @@ static sector_t __max_io_len(struct dm_target *ti, sector_t sector, return len; return min_t(sector_t, len, min(max_sectors ? : queue_max_sectors(ti->table->md->queue), - blk_chunk_sectors_left(target_offset, max_granularity))); + blk_boundary_sectors_left(target_offset, max_granularity))); } static inline sector_t max_io_len(struct dm_target *ti, sector_t sector) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index e96ba7b97288..4ff5886d3ca4 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -912,14 +912,15 @@ static inline bool bio_straddles_zones(struct bio *bio) } /* - * Return how much of the chunk is left to be used for I/O at a given offset. + * Return how much within the boundary is left to be used for I/O at a given + * offset. */ -static inline unsigned int blk_chunk_sectors_left(sector_t offset, - unsigned int chunk_sectors) +static inline unsigned int blk_boundary_sectors_left(sector_t offset, + unsigned int boundary_sectors) { - if (unlikely(!is_power_of_2(chunk_sectors))) - return chunk_sectors - sector_div(offset, chunk_sectors); - return chunk_sectors - (offset & (chunk_sectors - 1)); + if (unlikely(!is_power_of_2(boundary_sectors))) + return boundary_sectors - sector_div(offset, boundary_sectors); + return boundary_sectors - (offset & (boundary_sectors - 1)); } /** From patchwork Thu Jun 20 12:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705374 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 EE1C71AE85B; Thu, 20 Jun 2024 12:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888110; cv=fail; b=fLEI6i3PaAhPm66q2NyYvp3bDfu8h3VMNlFy7nXU5khEUQW5Khs+MlgX800CJfNcwkLf6w3t9M+ytLv7TRoFM/pUH70YXMOUg89GZkLwegK+5d3tdxhQrzhRlEnhhHEruL5DPSsqckicUB3wVpKqJt+TSmkqhpuDclyiGfEuM+k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888110; c=relaxed/simple; bh=TCmSWBzExXAZ5jcgtbZ16k8wVv/6IoqNpwGaVx3aORE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=dzD6sQfRSKRbFFuEBpmh8A+jBrolUlRALhlBuuFHAZxBgF43Uhs0uOlw2Bis+aCduZikLMjiDxjtl5ld1ZYvsKeZc9+aeB4jnvTKDG6MFoJ4AHrnw+xNHDY4qo2PnOptKvKJF6xBM5q+TM/Vi0ugwwaWXVikmPP1M3GIDnhZI4s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=lYGfUdEm; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=e6Tm2BF+; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="lYGfUdEm"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="e6Tm2BF+" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FJuY018262; Thu, 20 Jun 2024 12:54:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=l5F98DnsUI3BtppbdgEqyNw7d8YW99aVlWMgn0D5V7I=; b= lYGfUdEm9ckc48Nd4cEl1Nn1ao+nk/YEWtYs2Qx8Cw3++Uv4wcptec/atXNYGjjy 302aky7Br1bPzlhDhYesNOos4ngbu6UBGlgQDNjH+Zyy6rDKrkHOfG4U8AlOwE4b tPGgSS4yoQMQJz/NgkPjGyW35ZZtopilvPdhtZundhCuJoiTCSkEQPGM1cJRfw09 oH8py8CK5DfhC2LDsAkEyZ2HdX9lydJuRoRUEXXHSzBgZb7IPwTLRgv1vmc31yBd Scw9E1VYqrnNCOEu/Tt/RYWVZwUk7JQaX7tP2y9s61gMvncIrxIe8vWzBbm91/HP abjvHQnN8kGsRC4f1X1vuQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yujc0b43n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:32 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KCUOi3034795; Thu, 20 Jun 2024 12:54:31 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dap437-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B6rHq9sMuBlk6AKIAp5W2ERIEzTB9e+mq5E+Om3OqN+Y8MOVpkEYILH3tgl/yq0O8MDePJaHf07gFm9rtPtae+HXJ0O4ufA+yRhL9iXxDxnX/ix1BaCYpt53mYcCmAP+ArBm5JlDOxu4e2EF55JTaILQBYL7eAg56Rj6a9A2Iv105NvBqjXPb1py3zj177Qg+r/u4zgWNVVMzpG5Fd05ckb14KMmYnDx6vNGVTUFMndASHDQMkUkBJHOxmH+/lev6MyRuQgzJPLAKp7fuBBmKwX2wZf+BB8dEThGTpKkAtKYjMEoXZKgEqH8kqvY4Pfvme5yxHQe20YkSpNIFXZ6RQ== 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=l5F98DnsUI3BtppbdgEqyNw7d8YW99aVlWMgn0D5V7I=; b=YvSwrQoQ0Z9y/zI4fVJ8fsrtjQ5hgZ2Sku6BKKs914J+NCFbjoJSK3fTEB4G4J4o1CobAkaXBflOmQ9Q7l6jsnCSMukR2+PorVhr5uDAccBO542koJkwL60HnhSvY1uIDWepca0LkoM3K7N8RLYWuXeDxnYyKu6Glm8uqrQIZYlkTdx7jvqX+TvmsnG6S21Z1LiAmAINBDdkwy5cY73nsSLiyS+QpRtzNf3JHABB1aWYWmgjcRE9fJmykzNpPAZWi6mbVcZR2+T0EqDL64DwTc0R2xjk1IPbBRkLl9qU3H1JmWzuiDVlj3nzWrejmJyTSYh450p1/Bcg4k9wiQw2FA== 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=l5F98DnsUI3BtppbdgEqyNw7d8YW99aVlWMgn0D5V7I=; b=e6Tm2BF+hgdvd2LMp2LL1yJkYyHUryrjROv6vSPwIqd9cbFZ1cC7W+tqcYoGFYw67za3AF5UuS7LXjLbhWh4Sjorhn+/vwIwn7hXBkV9YHy3xweXWQRaLsOl1ZvwCYDlSeXc+IRPxdwAnWRzZPNhth/wDLNNGaE4J11SO42nBbk= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:28 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:28 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, Prasad Singamsetty , John Garry Subject: [Patch v9 03/10] fs: Initial atomic write support Date: Thu, 20 Jun 2024 12:53:52 +0000 Message-Id: <20240620125359.2684798-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR14CA0007.namprd14.prod.outlook.com (2603:10b6:208:23e::12) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: b5663466-c0a9-4966-7a11-08dc91281eec X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: a0Igq+Bt0wcmLlGWgvFXV4Nit+JbA4JAHu5/CIDTOYIdd0hN938tAI8JdFaIhMqMBNesDxWrZW6vUjBkwjd13xfNUqoU5rz1yA3gopFbc4t62hBpIwrrVF7eOUwPZcTy5JlgOj0QbLgU/Ri1RF9AbKAmTysCju9ntMEJnsmxRZs7QGJpC9pbZNMvRFzw3CAqrNnXkIACpZGW/98xnFcvYv7wo2xKMZtfKLUZ6yfXubaLPC4+d2zGmdo67SvxVDgZ6ulYYna3nVGEfoVPUNvIdB/czryyFfvTVbYeD7vJNILwf1ps07j1MMktqIZLqHOvaUtcM8qRA2VqyLbTAMY/7wW3YQquKfV3l3k+7yUIPZe3n1Z/cJ8qep3kW9iTACSB4zMzhNkXsLHpmrO+n9VsL+naEd4RpOfvcWWwPiTaI1LDWCOSVSpdG005Pe0jnzT7nUue05c/KNdjPkJsFj6MoSftTElnzX7bCwhugmC7VfEaK/TK4hEl8FryXVFdM4w1sMmSGQ9iruwpRrvDDIYWHpGDTACgMkBEaNq4SzBzM+pFOtatxSiNcGsE89iIe6EbCwvgvMwcXU528+ZGF77sjzi3LGJ6LipBEtfrsafGmVfUyOSJhpkCGyQyqKsRM6tKz4bfTY8c/I73eq6weEXOvWElHfvCmPOSRQ04rzOf4gEOzEblqB1mBNAs18htDFSiNV6PoO24UXdyXnthnM0sn6+85ZFly/1g2NC8Ct/+DTwpqIdCS4dZXwPV9UdLC4RolV8xCxDqCrYyn36sCvmzwHl6SmRlF/4h1mkpO8J8C1kaEL55kYSrZJB6fjHyTsbZNHUfk0GLVlUx8TPugFAYH7Ys0gMsQFF22R29pK2QCNbys+0K9EhTZzYbKUXnm4S5s9Aki+cEjKmg0TVYBF6frGuuRkMuF5qf3fsikTNDgS1VeW97pEHtPirCJp9du+0vLUcfeT9Hl4GtJk2bX1xW6J1K40HZz4aPOFOHRCLi+UDfId2AFg6IafAQ/mpxKcsTlMuusyln8tf2S/e+aFhtoy05NZfnly3bI3FCzFdcwDNQ57nMaLUrcKXG1SQhkAAg4qDGPKVFUxYsdpyiYyekUOo0bDiwdniggWDj4DM4AppuUugDX6wFPzTT2usgPtcTncMBBpIoXqd0gas6ho+PoaaWmDm/9BkwigauYnJClMglqO6nPS+I4b1WDt87QVvCoM2nL40qEFri5+riqCNyLkvaaWxJM5CmuzQ4tCQF6EVT8SNXZY4WFyfCoBleqV3fARK8p1Y5ANB6ZFBhcFVQxJzKVCEOdfL2fRO45GXTDxAk33n5Gr669x0031tyaXM7fzPUcxF40S/qOhOmUT3ni7bPsOmKqb1qAQ5bBOI8VL4= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8O23aJcIUbOjtfX3PDhODEFgXOLw0DY/CIz+umeILukAmRTIIMZZcJvVDd+L1RIDEB2HgCP92RmHk3TgNAz/UrxhvPbzFLmoXjw5XK1OQDq+wmqDUMjqwrUemorpr2lJdimSWweA3hsBNlOXTvZvNzSRfKY9utE13XKbLaaZcvsZpwDdZuVDXMxwUpboR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x2kRRw7dd+YEX01CCsPq0ZknP+T8kYgF920kw1IX0/OmJVDMJHApK7YyQcYyjyvMTiDlTvwhVlc0EwA0aYDZiemw1ga4jovbMqKwZlLg1weGVPZvRBq08+tEhMypgkqf9Y2d8H/OY5F4A4ObJW5KOyk5EANwe6XQBR3l2kjpmMJamJ01lBqzeCCBKltQ1i4q/eJP0epf1LJ2yOY8oTCvSE3cb636L7iLFioGpoJKgYFnMhkTJnBNX7mJg8fRZVkFdRRyOYfZiVq542vDRgpOAgO0UCzJuKEGQvxwUvkfrVCw3OmmUfnGaS9PdOlTSjYFiuthYJ7gpXrW4otihJowan8C59v1g65Pf3WQ6TApug== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 8iBFkcdLnzSC0VjYwebjMJYfB2B3wny3LV1EZv2EoeOpnonDONoxjKupRnruXKRLc07LC6tZP4tzI8QSGtx+L2bxcmfMY1WKeJaUq8r4eEnk0/wRlUrqsnnpOE/RwGcpz6YgrDsa1W8nxFDfMJTCY+clgrVUkFAFuy/iP0HmDrV6hHdrQHtb3n2hV/MQmbJufNj+tJ9CkwzC2qGSnP4O9vjbgDpjlji/aYaFUT52PScVKEhSxQ/VoLbcDz/a/rtc+B3oeM/UIYvFJUB3gbNlsokdYD7MfowrQ1qEgWxvQ2INvv9rGu1cHIR3Y22tBf+177AT/Zkp4iCHHVSZV64SGtKcdHBRjLPbjURWrmaaPb7H8D+ZvZPdMopi6yDaLVHdw1yhKVwGOzM5dpCzbD6TQoaAixL4/MrpMo4JJELC9El49890RXzmv6OvpCwXP2UZw4oDUrQMLMMr1A7v/O7tQvcaWfGkmDAddYR0/Tu10xZWg0vDGwf5G2stc41Jrrri57Uw3dTvaaw1UH3A/CxKmx41/5lqnJyLZLP3N4+sk7VKyBMamOkjxMAxqGSzaybha/S9JZGWYEFVbQ/jlYD+PNA+9heOgjEjeKN1IeUyAHU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5663466-c0a9-4966-7a11-08dc91281eec X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:28.4271 (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: rqhryiMVExD9fAIIBHqsWWQaGxIC1VStoRfNCYYmyM5nQQOYzoGXCDii6vEtoSyb6r74cM3Mxx+ANvoKcnLgzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-ORIG-GUID: 7xa28vK4-_6mFWORWL-qsKzFqzDq2zbj X-Proofpoint-GUID: 7xa28vK4-_6mFWORWL-qsKzFqzDq2zbj From: Prasad Singamsetty An atomic write is a write issued with torn-write protection, meaning that for a power failure or any other hardware failure, all or none of the data from the write will be stored, but never a mix of old and new data. Userspace may add flag RWF_ATOMIC to pwritev2() to indicate that the write is to be issued with torn-write prevention, according to special alignment and length rules. For any syscall interface utilizing struct iocb, add IOCB_ATOMIC for iocb->ki_flags field to indicate the same. A call to statx will give the relevant atomic write info for a file: - atomic_write_unit_min - atomic_write_unit_max - atomic_write_segments_max Both min and max values must be a power-of-2. Applications can avail of atomic write feature by ensuring that the total length of a write is a power-of-2 in size and also sized between atomic_write_unit_min and atomic_write_unit_max, inclusive. Applications must ensure that the write is at a naturally-aligned offset in the file wrt the total write length. The value in atomic_write_segments_max indicates the upper limit for IOV_ITER iovcnt. Add file mode flag FMODE_CAN_ATOMIC_WRITE, so files which do not have the flag set will have RWF_ATOMIC rejected and not just ignored. Add a type argument to kiocb_set_rw_flags() to allows reads which have RWF_ATOMIC set to be rejected. Helper function generic_atomic_write_valid() can be used by FSes to verify compliant writes. There we check for iov_iter type is for ubuf, which implies iovcnt==1 for pwritev2(), which is an initial restriction for atomic_write_segments_max. Initially the only user will be bdev file operations write handler. We will rely on the block BIO submission path to ensure write sizes are compliant for the bdev, so we don't need to check atomic writes sizes yet. Signed-off-by: Prasad Singamsetty jpg: merge into single patch and much rewrite Acked-by: "Darrick J. Wong" Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Hannes Reinecke --- fs/aio.c | 8 ++++---- fs/btrfs/ioctl.c | 2 +- fs/read_write.c | 18 +++++++++++++++++- include/linux/fs.h | 17 +++++++++++++++-- include/uapi/linux/fs.h | 5 ++++- io_uring/rw.c | 9 ++++----- 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 57c9f7c077e6..93ef59d358b3 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1516,7 +1516,7 @@ static void aio_complete_rw(struct kiocb *kiocb, long res) iocb_put(iocb); } -static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb) +static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb, int rw_type) { int ret; @@ -1542,7 +1542,7 @@ static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb) } else req->ki_ioprio = get_current_ioprio(); - ret = kiocb_set_rw_flags(req, iocb->aio_rw_flags); + ret = kiocb_set_rw_flags(req, iocb->aio_rw_flags, rw_type); if (unlikely(ret)) return ret; @@ -1594,7 +1594,7 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb, struct file *file; int ret; - ret = aio_prep_rw(req, iocb); + ret = aio_prep_rw(req, iocb, READ); if (ret) return ret; file = req->ki_filp; @@ -1621,7 +1621,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, struct file *file; int ret; - ret = aio_prep_rw(req, iocb); + ret = aio_prep_rw(req, iocb, WRITE); if (ret) return ret; file = req->ki_filp; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index efd5d6e9589e..6ad524b894fc 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4627,7 +4627,7 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool goto out_iov; init_sync_kiocb(&kiocb, file); - ret = kiocb_set_rw_flags(&kiocb, 0); + ret = kiocb_set_rw_flags(&kiocb, 0, WRITE); if (ret) goto out_iov; kiocb.ki_pos = pos; diff --git a/fs/read_write.c b/fs/read_write.c index ef6339391351..90e283b31ca1 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -730,7 +730,7 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, ssize_t ret; init_sync_kiocb(&kiocb, filp); - ret = kiocb_set_rw_flags(&kiocb, flags); + ret = kiocb_set_rw_flags(&kiocb, flags, type); if (ret) return ret; kiocb.ki_pos = (ppos ? *ppos : 0); @@ -1736,3 +1736,19 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out) return 0; } + +bool generic_atomic_write_valid(struct iov_iter *iter, loff_t pos) +{ + size_t len = iov_iter_count(iter); + + if (!iter_is_ubuf(iter)) + return false; + + if (!is_power_of_2(len)) + return false; + + if (!IS_ALIGNED(pos, len)) + return false; + + return true; +} diff --git a/include/linux/fs.h b/include/linux/fs.h index 0283cf366c2a..e049414bef7d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -125,8 +125,10 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, #define FMODE_EXEC ((__force fmode_t)(1 << 5)) /* File writes are restricted (block device specific) */ #define FMODE_WRITE_RESTRICTED ((__force fmode_t)(1 << 6)) +/* File supports atomic writes */ +#define FMODE_CAN_ATOMIC_WRITE ((__force fmode_t)(1 << 7)) -/* FMODE_* bits 7 to 8 */ +/* FMODE_* bit 8 */ /* 32bit hashes as llseek() offset (for directories) */ #define FMODE_32BITHASH ((__force fmode_t)(1 << 9)) @@ -317,6 +319,7 @@ struct readahead_control; #define IOCB_SYNC (__force int) RWF_SYNC #define IOCB_NOWAIT (__force int) RWF_NOWAIT #define IOCB_APPEND (__force int) RWF_APPEND +#define IOCB_ATOMIC (__force int) RWF_ATOMIC /* non-RWF related bits - start at 16 */ #define IOCB_EVENTFD (1 << 16) @@ -351,6 +354,7 @@ struct readahead_control; { IOCB_SYNC, "SYNC" }, \ { IOCB_NOWAIT, "NOWAIT" }, \ { IOCB_APPEND, "APPEND" }, \ + { IOCB_ATOMIC, "ATOMIC"}, \ { IOCB_EVENTFD, "EVENTFD"}, \ { IOCB_DIRECT, "DIRECT" }, \ { IOCB_WRITE, "WRITE" }, \ @@ -3403,7 +3407,8 @@ static inline int iocb_flags(struct file *file) return res; } -static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) +static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags, + int rw_type) { int kiocb_flags = 0; @@ -3422,6 +3427,12 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) return -EOPNOTSUPP; kiocb_flags |= IOCB_NOIO; } + if (flags & RWF_ATOMIC) { + if (rw_type != WRITE) + return -EOPNOTSUPP; + if (!(ki->ki_filp->f_mode & FMODE_CAN_ATOMIC_WRITE)) + return -EOPNOTSUPP; + } kiocb_flags |= (__force int) (flags & RWF_SUPPORTED); if (flags & RWF_SYNC) kiocb_flags |= IOCB_DSYNC; @@ -3613,4 +3624,6 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len, extern int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice); +bool generic_atomic_write_valid(struct iov_iter *iter, loff_t pos); + #endif /* _LINUX_FS_H */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 45e4e64fd664..191a7e88a8ab 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -329,9 +329,12 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO negation of O_APPEND */ #define RWF_NOAPPEND ((__force __kernel_rwf_t)0x00000020) +/* Atomic Write */ +#define RWF_ATOMIC ((__force __kernel_rwf_t)0x00000040) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND | RWF_NOAPPEND) + RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC) /* Pagemap ioctl */ #define PAGEMAP_SCAN _IOWR('f', 16, struct pm_scan_arg) diff --git a/io_uring/rw.c b/io_uring/rw.c index 1a2128459cb4..c004d21e2f12 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -772,7 +772,7 @@ static bool need_complete_io(struct io_kiocb *req) S_ISBLK(file_inode(req->file)->i_mode); } -static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) +static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type) { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); struct kiocb *kiocb = &rw->kiocb; @@ -787,7 +787,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) req->flags |= io_file_get_flags(file); kiocb->ki_flags = file->f_iocb_flags; - ret = kiocb_set_rw_flags(kiocb, rw->flags); + ret = kiocb_set_rw_flags(kiocb, rw->flags, rw_type); if (unlikely(ret)) return ret; kiocb->ki_flags |= IOCB_ALLOC_CACHE; @@ -832,8 +832,7 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(ret < 0)) return ret; } - - ret = io_rw_init_file(req, FMODE_READ); + ret = io_rw_init_file(req, FMODE_READ, READ); if (unlikely(ret)) return ret; req->cqe.res = iov_iter_count(&io->iter); @@ -1013,7 +1012,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) ssize_t ret, ret2; loff_t *ppos; - ret = io_rw_init_file(req, FMODE_WRITE); + ret = io_rw_init_file(req, FMODE_WRITE, WRITE); if (unlikely(ret)) return ret; req->cqe.res = iov_iter_count(&io->iter); From patchwork Thu Jun 20 12:53:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705370 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 60B1D1AD401; Thu, 20 Jun 2024 12:55:02 +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=1718888104; cv=fail; b=d6LIFwj+OwgDdhE3YBf10ptTemt1aiVKTNvZmHMHnVAj5RxXSMvjODK1/zFRyO8lRzRc8RaFPg7mA0UbNvI8nc2/tvZXjh+hwtHqo3+6Lzqk/QKl9/iDcnTTQqGjGfXfePPD2cXxqhQx2DM9vzJO5hpzEhz9MlZO2SbAhvGD3Tk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888104; c=relaxed/simple; bh=4sAdZ7JGrNueCiAtuiL3imnkmCYjJN/4P3Ks8wSpm6w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ds7cWLP87nzjUSN6Gd5G96vkSuOKKJ0ZkXVurK/5fN67WnlHOitId5XIbEHOvJQHMBLR4UO0WZgOY6cxeF8yLVuXf0oeCcdI/Tj0O7hanwlO/3HRizomxx03Cm9uCp4alCtkUdvrQbWuXDxDiQWS+qiOZvrTOPdmmIhS+4lDvqo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=gHmgrgif; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=qByZpuXw; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gHmgrgif"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="qByZpuXw" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FPNB005039; Thu, 20 Jun 2024 12:54:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=PSQ2jv+p47f4uHMaH38L57CFpLn4SsXZ/p0FSibYjk8=; b= gHmgrgifzeqpnhc7fPxU/RUTHztQbMQqFy5PMGBq96+r+o+oC/GcaXWzWdkd4ZD8 3TsdZBaVJBERyS356XsnfKzyCei2MCAKne8A/jcMeMC9J9oQ23DbQ2OPFYAZIY6l coeFF24dR4k9lWJs1mMNsEkrweLS/UNKuPMcMCFjelbK+jvYm+yk7iRnplJUPZD0 ZCKSA+Q4JDu8J0QOCMkan2Ypi7973BbgYEDe0eUvFRHEwgRU33kw6VvCnCvpKiZm AjPYHro/vugLVph4q4UrAtB5itqRKAfARiseYJ7hGRBSgrcBsHwfFTK35vsCBx84 81xIjq9T3aOJSxTLvdabPg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9ju2v4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:34 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KCbFwx032811; Thu, 20 Jun 2024 12:54:33 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2040.outbound.protection.outlook.com [104.47.56.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dae6hc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dr0sX5fFwZd0/DtUtfaDlxG7BXNZVaZXTbnecrkJy/OzRCbGo3uI9RyNszUplsjbSjigCJVFOks13GNMT/Av0cFSrQdd/+KM29DLYx383i7X60XNSHoNkl7xZQ2mvNCJghyNidXLJX0PuD7eptWENaUfSwFb62wvSlZDDMTGM/k8p94kZBiPbnhqGzk37EFzxR6t2l3xOjgtjv2JYL1w66DTi51lYw4y2wN1m3rQPfZNjvgX7X0zjho2U/ug/TzN8efWsEb8YuOc4qYi2CNdIkEq+bmdwaVG5TJjnKPTxDtEp+RYC2WGNSrTHJ8vl91ok7YGejSrc0M7bWNTLcmlhw== 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=PSQ2jv+p47f4uHMaH38L57CFpLn4SsXZ/p0FSibYjk8=; b=kR+4pGhPBi3SHYExdfyi67cTRsxPmLWxjzC/xDCn4KJMmQdFzTRPEGlZczX3lt9HJ+BaoFKagw7ruFitbtOf+L/HFlt5IwhJsaLg6eUrqatfslkNo9NwYPc2wIkkAclxz2x9eAOC9wMbwexPN12uf6daGc/i2GG+HwJsYeLD9O/w1Se/OLSr4DP43oOSysl3S+CCVfbxvNCbDAr86X+UWKmGRsPfenvGwYpIjbSpmLTGi6hlyepjJgWORZYmX67j1LV2XSg23xZpO31N9nNi20eKGNOiOu5cq0hmcoS0ma/kriaZZ6p73WYQvslpJgGDKJPdu6Vwv4miDG7jAEDfKQ== 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=PSQ2jv+p47f4uHMaH38L57CFpLn4SsXZ/p0FSibYjk8=; b=qByZpuXwJn09huoPpvo9ETrNZ7ZEU893FgWWasORizIymt6RRSlGd+qy+RR4ZhfydpRNOOkv1jzNiXAH+wGw0te5qAZp9o8GIStg7qLeSef7/sYSMGca8TuA1pX5YL1sYYIOFhVRo9nAv7uyzQTOum8obQyfk47toSQoYaSr1ck= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:30 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:30 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, Prasad Singamsetty , John Garry Subject: [Patch v9 04/10] fs: Add initial atomic write support info to statx Date: Thu, 20 Jun 2024 12:53:53 +0000 Message-Id: <20240620125359.2684798-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL0PR02CA0106.namprd02.prod.outlook.com (2603:10b6:208:51::47) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: ce2f1395-0937-4e19-506b-08dc9128203e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|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nu3M6cMT5VYySD6fWaK0e/Qr+oHAoRFjkqz/tMhcY+LWjwSQc8d9e/wK5fQ4CMoeeXgTPmMOiMBgQox80muFElppOgDfNHYwL+4oHYaPk1lFXUcK9mo78IzE9poRkGOeEHZei7Zuh2bZlpPq4eY4FDl0ST/+ReurR8nv/bNBlkn+mKGPMBuhNjVVixg4WeSsDdjKWA3imU1tcVYvWYb7SVtJiIni8TFARsjpUPjo6iUiN5vXq8dUQxTEGWAFW4tZC4CbPBBI7iZ9M/lUjZlDocIKuQHuKK48UC+or3uKIpcXdLcDn0YE/mQN0dR3Nv+Z05CnAPAJgJQMqhv6cIHmrc= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5k2tUch9JgXgnKiQW52QgR6gI1F3SV6vMRKkhIO2Yat+vjo+5ZfYBU2499p9PUKzmUNKFj0axYHkGhlLJWkU9cEOtf+9F1lzaCStOH8oo+ICyzOsxl6a3/R9BjHxppdLXuy6zRUQZm5nCjBzDJqKloAkmOIHMALi6Cy7s1hh7e8/ByC8xn+y6ua/kNOwoy/dA1kEhOMKwekU9zbTaiPE4RVhtw9QJ0JzgtjN+jeyd0muTXnyE51dRDOTOBjO6EU5xT26ZR5G+DlD6boALUJFhJSbqyG7klyDMAK6MyP/K+Ys6ieojVIaHEAdIxkx9VdCccokfsOBg6kVeBgLhNQR8C6SWLL2mEYUfEK5hmLBLTf5id7KX9llSczLBMPYttmKG31/Iy6s4bmQWTuXTiP8TGRuzhyzSOa6D/W67MchFMFHpucn8LHI61a0RI6TcCOLtx1W71APH8eb5QJaxPFG3h6Wc/AdUZ4+CgimtL7oOadnnmnRfzeLohYYVI0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vWpY1W0G2/jUCC47YQwcaWD7UP1ddvuwaQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: MEApo3mIkd+y1k4EOP8E/zRzhlNucV/dzAJydasydfc3VD68aZj8AO0Hzpy6cfLPL+/O5TJbJNoKW2WG35aWMkuE5zfJya70GVxXCOPPOUru8IGpJdeYZqf/UPd0SoKgtnirFzN9/c+3+9IzYZ/Z01GR8Ru+PaMEfXAPYlrkwk7KQwcMcgdaOZ6IZp1M4dXKUrQG2e3whcp1Aw1sJa5HxYJChYTjSL2VjemFj1BML5CbAwNHCb5GUJrCoIAFW+LcG/sGRqIz6rAZD+hcqgbZQl6SJ0G7IA/66sLk6sqHHAp/PNTC1V3wbeaazeKZZWs6cCRrYLeiCjntQvk0y4+hhxif0Odjot9lXOovdjKehw3iv1iCPfdUBBdiO0mMcdy2dZMBUIFYwdJuV/uP70L8EA7FE0N6nmNkluTwdDgrYo+h+Btx14AjyymmoBk2paMOrjrVmyxCDLErF+68XsUGNaQ6XWj1fOVF29kriVXaFjAQPJuV3HFolD4RyNwi9ySYr0A+ia/oTykHy+qHtPKI4nrnJLCVsJnr37k0sI2VSiEeo9qwcQwyDauWtk5/OCj2MpPILtVLXXNNvBEpBolC+VyRPPReS3UMilcyBGKVyFc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce2f1395-0937-4e19-506b-08dc9128203e X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:30.6645 (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: LzeI7Sk+e7MJrURFN68LVZ35HadzNaguXcJezkYZlS6/aQgDcH0KIfyTMwtKXIqsQe1N+Zf+56OMnRWjmM+45A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-ORIG-GUID: 94apZO_kQAhPOfpufH0JUnVJPsAd7Zcv X-Proofpoint-GUID: 94apZO_kQAhPOfpufH0JUnVJPsAd7Zcv From: Prasad Singamsetty Extend statx system call to return additional info for atomic write support support for a file. Helper function generic_fill_statx_atomic_writes() can be used by FSes to fill in the relevant statx fields. For now atomic_write_segments_max will always be 1, otherwise some rules would need to be imposed on iovec length and alignment, which we don't want now. Signed-off-by: Prasad Singamsetty jpg: relocate bdev support to another patch Reviewed-by: "Darrick J. Wong" Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Hannes Reinecke --- fs/stat.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/fs.h | 3 +++ include/linux/stat.h | 3 +++ include/uapi/linux/stat.h | 12 ++++++++++-- 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/fs/stat.c b/fs/stat.c index 70bd3e888cfa..72d0e6357b91 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -89,6 +89,37 @@ void generic_fill_statx_attr(struct inode *inode, struct kstat *stat) } EXPORT_SYMBOL(generic_fill_statx_attr); +/** + * generic_fill_statx_atomic_writes - Fill in atomic writes statx attributes + * @stat: Where to fill in the attribute flags + * @unit_min: Minimum supported atomic write length in bytes + * @unit_max: Maximum supported atomic write length in bytes + * + * Fill in the STATX{_ATTR}_WRITE_ATOMIC flags in the kstat structure from + * atomic write unit_min and unit_max values. + */ +void generic_fill_statx_atomic_writes(struct kstat *stat, + unsigned int unit_min, + unsigned int unit_max) +{ + /* Confirm that the request type is known */ + stat->result_mask |= STATX_WRITE_ATOMIC; + + /* Confirm that the file attribute type is known */ + stat->attributes_mask |= STATX_ATTR_WRITE_ATOMIC; + + if (unit_min) { + stat->atomic_write_unit_min = unit_min; + stat->atomic_write_unit_max = unit_max; + /* Initially only allow 1x segment */ + stat->atomic_write_segments_max = 1; + + /* Confirm atomic writes are actually supported */ + stat->attributes |= STATX_ATTR_WRITE_ATOMIC; + } +} +EXPORT_SYMBOL_GPL(generic_fill_statx_atomic_writes); + /** * vfs_getattr_nosec - getattr without security checks * @path: file to get attributes from @@ -659,6 +690,9 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_dio_mem_align = stat->dio_mem_align; tmp.stx_dio_offset_align = stat->dio_offset_align; tmp.stx_subvol = stat->subvol; + tmp.stx_atomic_write_unit_min = stat->atomic_write_unit_min; + tmp.stx_atomic_write_unit_max = stat->atomic_write_unit_max; + tmp.stx_atomic_write_segments_max = stat->atomic_write_segments_max; return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; } diff --git a/include/linux/fs.h b/include/linux/fs.h index e049414bef7d..db26b4a70c62 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3235,6 +3235,9 @@ extern const struct inode_operations page_symlink_inode_operations; extern void kfree_link(void *); void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *); void generic_fill_statx_attr(struct inode *inode, struct kstat *stat); +void generic_fill_statx_atomic_writes(struct kstat *stat, + unsigned int unit_min, + unsigned int unit_max); extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int); extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int); void __inode_add_bytes(struct inode *inode, loff_t bytes); diff --git a/include/linux/stat.h b/include/linux/stat.h index bf92441dbad2..3d900c86981c 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -54,6 +54,9 @@ struct kstat { u32 dio_offset_align; u64 change_cookie; u64 subvol; + u32 atomic_write_unit_min; + u32 atomic_write_unit_max; + u32 atomic_write_segments_max; }; /* These definitions are internal to the kernel for now. Mainly used by nfsd. */ diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h index 67626d535316..887a25286441 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -126,9 +126,15 @@ struct statx { __u64 stx_mnt_id; __u32 stx_dio_mem_align; /* Memory buffer alignment for direct I/O */ __u32 stx_dio_offset_align; /* File offset alignment for direct I/O */ - __u64 stx_subvol; /* Subvolume identifier */ /* 0xa0 */ - __u64 __spare3[11]; /* Spare space for future expansion */ + __u64 stx_subvol; /* Subvolume identifier */ + __u32 stx_atomic_write_unit_min; /* Min atomic write unit in bytes */ + __u32 stx_atomic_write_unit_max; /* Max atomic write unit in bytes */ + /* 0xb0 */ + __u32 stx_atomic_write_segments_max; /* Max atomic write segment count */ + __u32 __spare1[1]; + /* 0xb8 */ + __u64 __spare3[9]; /* Spare space for future expansion */ /* 0x100 */ }; @@ -157,6 +163,7 @@ struct statx { #define STATX_DIOALIGN 0x00002000U /* Want/got direct I/O alignment info */ #define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */ #define STATX_SUBVOL 0x00008000U /* Want/got stx_subvol */ +#define STATX_WRITE_ATOMIC 0x00010000U /* Want/got atomic_write_* fields */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ @@ -192,6 +199,7 @@ struct statx { #define STATX_ATTR_MOUNT_ROOT 0x00002000 /* Root of a mount */ #define STATX_ATTR_VERITY 0x00100000 /* [I] Verity protected file */ #define STATX_ATTR_DAX 0x00200000 /* File is currently in DAX state */ +#define STATX_ATTR_WRITE_ATOMIC 0x00400000 /* File supports atomic write operations */ #endif /* _UAPI_LINUX_STAT_H */ From patchwork Thu Jun 20 12:53:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705376 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 1F8CE1ACE76; Thu, 20 Jun 2024 12:56:09 +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=1718888172; cv=fail; b=BPbMTQviKkOrR1QMZ+X8hKTWZbo/ADM/rGRP8qtjaIQ4EsDICKgZfXu8c7gEhXvL1J/gGafd95nRcTCMOiEHBj83SUHckbC3j9jxcVsl+gNLjhUaUTQOIyLhTfiCbxyarjed14ZuDAhd3y2R3NgB3uR5R6yoLoOp4kcSEsyc31g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888172; c=relaxed/simple; bh=MBSLZXCGPswbj5Ji5qHqFHaBodyKmw1NJwKarTGj2/8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ItFDg4pHh0tJtRcNc0EJeRy0u0inVwis+K1/VIkYU8hJT0nHVo6dxcK3IkYVcHM0eZs0bYsvWMndVRmwboaMXlkuXB6vQiJD+cukWlwNGaNLvWrXeMIHUguhw4eacLN9lwFxcDLaoJgwAH7lfsWIGEvHIsfj3vuMTMqw/xnk+v0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Kv83NW30; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=PUugbRjy; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Kv83NW30"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="PUugbRjy" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FjjW014911; Thu, 20 Jun 2024 12:54:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=hKEsTIi4kwQMcHsGvo+ulq4GZSRO5ofNKcQ8PU1sS9g=; b= Kv83NW30UNffzAtL07V7Hz4XUhYRmEp91bf8SE/rogGP7Cl15PRFEUxuO7xBOnJC LVupg59x0z1/r/CsbigEfZ1jw62N7D1c6AgH20KggnDkjdewKlC+kwr+7QWD62X3 4Fswqqe/9g4YFnwz2RR0OoZNlesJ8D+0M5Jb2xJYM64JrNOEOIkqn27Ktz0Dn0i9 /ddwIcCwz89uS47vz/ZG/vsz0sAxzfZozqoZqgCyvMLNebhe3NBMFilGYCiQjIq1 R8kkTxlIP57EhDrespKBDt2OieoRIP4uc1j/AV7LW/9frEUGSBIUqCW0UrFU4ed1 Ql6o8WuNqmEq3yrAX03wqQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9gk54b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:35 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KCbFx0032811; Thu, 20 Jun 2024 12:54:34 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2040.outbound.protection.outlook.com [104.47.56.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dae6hc-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LrdDvB9PrBpLwbfhqh2PSEynzNYevxEW6bOL6F7tlKUWnVPWvIsXh/tGL9axVvnNAMy/8hCIeR2EJWG3PGluJo41qU+LBFu/IBloDCbKU4efm2PLX1D/ak8XqS7s0xiUVgj9HrPli3ATtg/0Ao4FFO4mGjQ7nI3FfsJ7tRrqBvuEqygFZNLRCoxuMQOUZVvbdhS6RyFg0j4AtM9ZW3fGqckZq+yTK/PFnUtrlE1d5ZmgFkZWG9gTc/8DRMtzWei+KayzPL8Ylwj+QVo7wCAKHjiWd9r5olrpzNEu15HZwcIEsWPW0RZiSkf0CZp4tyFGaAiJtHCFNBgoX+ImVcfzLw== 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=hKEsTIi4kwQMcHsGvo+ulq4GZSRO5ofNKcQ8PU1sS9g=; b=mV90fniL4ENaRfK7U4HHjvEkg7GdfKNtG1/l/zRxYAd/fOB0mbou9LOjHgsVlIk6NlMv/MM8TLYP8z53jgttMMkx+EbOS67JWF2P8DpCMXJXNbNm1yDAWCfaHAzVThNoBOSpXo2oV9iHQSASgU1ITUzbvqpOrAOWPdgq1/tMPWcQB7EuDjDQedXzRWGGMYEjMiWBJhN4NY3grWqhi7lOCr3dBu9fKJGUW8lSHm65BtNfe1RlgECWi3lqLjgCT2ny21TjPbSgN/8oLhj95LHNuWeXBs+hwfWsY7rFn/EBuRGJsdkS4wPQ3xrlgJnVA39n7f2btnW0IgX+HXiPaKFIsg== 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=hKEsTIi4kwQMcHsGvo+ulq4GZSRO5ofNKcQ8PU1sS9g=; b=PUugbRjyEQMOgDq+3/ZhVssYkNvKRmTMbLyv76/EbkbNwRaSUyNblIpGFgSe+ep81lSEhWZ5b5ewHmuvFGPbYfI7CIkLtskQRQGkxAJX7hMSUyUINNZljq9DrVT7TXPTehT0NLmLqkRrT48W+5Lerhmydjx1NNvdTcO6y9bxsm4= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:32 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:32 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, John Garry , Himanshu Madhani Subject: [Patch v9 05/10] block: Add core atomic write support Date: Thu, 20 Jun 2024 12:53:54 +0000 Message-Id: <20240620125359.2684798-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL0PR1501CA0002.namprd15.prod.outlook.com (2603:10b6:207:17::15) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: 798024fe-376c-4861-319a-08dc91282104 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: 9lph+fVJ0NWzSJfv3kQa4NAoZjI7HSw5sk9FXh89y+Yp/tE0BUffd4K8/+dVuKTRICjrLhDQZBl8gz5oVpjeOpMLO8T/nMczuQkkdNvN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Jsghz9NbgA+WhiATUtKN9TPzhtwR5S3CpPURaMBx3zzhCqwEIvS2ZTXTEr2eHkLqnuROGyPyt68qWkOxlH9tnZMomKYJPPaF4uPl4CVUjsR8MQXC0wOySCk/uri0gnN+mB+Q3gcPmj2YcwlSRhwWYW7G7aRMhMbeokyE6MJb5Hh8VVKyhbC9Kz6omSeVbPRcjA= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cKj/BpesXwdcjA3ef//00MhTVyC+mtvtBRIfHWIwfBcUdBIsNQEYeE8wjpcZGs4q/PgaryDqewhpofKWhRcfBYC+oQeDVH3bR6EOeIT+RIW4hGamIqJaSoHoYkoxMlH6pp+B7FzjZOhGVRSMXg93GHCokwKo51Fv5ufAt007/Lr9Ao6D3GsAKIOLjHKJ27VcWa3jz8s4leGnTkx3Zu53d+GS1RAFtjQAqQjjhjoAhOf7rQxEwP+kprrJFqRIl9aOtkToEvyhpotb27M7Jf9HCZ7isw6HfrOtFAw5j0t4hVESsSJ987WJ43IaRmAKJd6GbDB1l2M89G+QbllFs2A0XPI3UYkTfKuRspWYwSHQNJcpEMZe41L5yTTxAtE6K6hBH9uEf80rXpffiAaaol79jc1S9EFfkl1S+jfKmr2UZ84hwlj7KzwaFgbT24JQtNMF718Q0hwLtvnGI2lVLD0ypD1slqNiLzq/QQ63O0RTJpKNmfXq3wsTy2Pte9LDdmguCmImJMR2yv9CAj6+/K75wALLRsZOY4mQGCsvOCuiWT8henYfEWCqe1tAvmtS4QP+vDI4c+92n/8eqIGqeBMn0aePuabhZ6MmRKG1LaA0K7OOtlA5wXviyhdjv8IpPaMoAy34lrkYRLjmoBK3tneKS6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XS5GMeVddlFZz5wB6wnrw+ZMxvIbDjqtDK9nZnZ68E3Hoc5NdcUFJ4+h3vg/fgHiHWyqjcfF6LT0teb6+SCt2vcAqfqfD6up+JAkAfBcY3IxW70J5DWZrc79oHrv9B507WAKUSNvv0fKTh/oy5F6kv8rtjqGuSZlSEfjM79oa5Ld9ZkZ9VucPKatkvwVWdpnMT2ZUPHvl7f/VT9Jp2Sh5YjysahJcULeM9+BjFrOsOHneQqKQTw5NUA+ClXkf5ZSKpp/niQugJ1m/DM/HqEmT6gN1XHqiFkdObACn318vyOacl93u3RE19CjLOgwT6GoQnuGNVSA6L1xTLU963SMCzj73b2icQbZ31KCiBDnrMkmZ7qHGcGroe4hnFxQB/sKU+FlKSldKo7o2wP2IS5Mjww5jOD5O3qSH0Xx0bcYes6sn8qLpcqtuxt1+WfyYPfGjt/0UhQSHM1psqQmCf0qu+u+jbbJ8atypHJMCrTpPw89vISKKQ0UIHv3mdcW2wyn3sSkXMcS8WhkAWMAvcb/cUlRXgt42rbbTFasNH8CdU0jAKeBJqmacnP9jLQHm8bX76XM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 798024fe-376c-4861-319a-08dc91282104 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:31.9653 (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: GxNpLaB+CyvdvT5kzxQpHUXH72V39e+lLOeYplVdZF8rbrSaQJguSHBaifYnmgWqtViq9VA0a5vgccyDfdjWzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-GUID: GKvkbmgKIevC4R35Lj79prY4lRd3zFl9 X-Proofpoint-ORIG-GUID: GKvkbmgKIevC4R35Lj79prY4lRd3zFl9 Add atomic write support, as follows: - add helper functions to get request_queue atomic write limits - report request_queue atomic write support limits to sysfs and update Doc - support to safely merge atomic writes - deal with splitting atomic writes - misc helper functions - add a per-request atomic write flag New request_queue limits are added, as follows: - atomic_write_hw_max is set by the block driver and is the maximum length of an atomic write which the device may support. It is not necessarily a power-of-2. - atomic_write_max_sectors is derived from atomic_write_hw_max_sectors and max_hw_sectors. It is always a power-of-2. Atomic writes may be merged, and atomic_write_max_sectors would be the limit on a merged atomic write request size. This value is not capped at max_sectors, as the value in max_sectors can be controlled from userspace, and it would only cause trouble if userspace could limit atomic_write_unit_max_bytes and the other atomic write limits. - atomic_write_hw_unit_{min,max} are set by the block driver and are the min/max length of an atomic write unit which the device may support. They both must be a power-of-2. Typically atomic_write_hw_unit_max will hold the same value as atomic_write_hw_max. - atomic_write_unit_{min,max} are derived from atomic_write_hw_unit_{min,max}, max_hw_sectors, and block core limits. Both min and max values must be a power-of-2. - atomic_write_hw_boundary is set by the block driver. If non-zero, it indicates an LBA space boundary at which an atomic write straddles no longer is atomically executed by the disk. The value must be a power-of-2. Note that it would be acceptable to enforce a rule that atomic_write_hw_boundary_sectors is a multiple of atomic_write_hw_unit_max, but the resultant code would be more complicated. All atomic writes limits are by default set 0 to indicate no atomic write support. Even though it is assumed by Linux that a logical block can always be atomically written, we ignore this as it is not of particular interest. Stacked devices are just not supported either for now. An atomic write must always be submitted to the block driver as part of a single request. As such, only a single BIO must be submitted to the block layer for an atomic write. When a single atomic write BIO is submitted, it cannot be split. As such, atomic_write_unit_{max, min}_bytes are limited by the maximum guaranteed BIO size which will not be required to be split. This max size is calculated by request_queue max segments and the number of bvecs a BIO can fit, BIO_MAX_VECS. Currently we rely on userspace issuing a write with iovcnt=1 for pwritev2() - as such, we can rely on each segment containing PAGE_SIZE of data, apart from the first+last, which each can fit logical block size of data. The first+last will be LBS length/aligned as we rely on direct IO alignment rules also. New sysfs files are added to report the following atomic write limits: - atomic_write_unit_max_bytes - same as atomic_write_unit_max_sectors in bytes - atomic_write_unit_min_bytes - same as atomic_write_unit_min_sectors in bytes - atomic_write_boundary_bytes - same as atomic_write_hw_boundary_sectors in bytes - atomic_write_max_bytes - same as atomic_write_max_sectors in bytes Atomic writes may only be merged with other atomic writes and only under the following conditions: - total resultant request length <= atomic_write_max_bytes - the merged write does not straddle a boundary Helper function bdev_can_atomic_write() is added to indicate whether atomic writes may be issued to a bdev. If a bdev is a partition, the partition start must be aligned with both atomic_write_unit_min_sectors and atomic_write_hw_boundary_sectors. FSes will rely on the block layer to validate that an atomic write BIO submitted will be of valid size, so add blk_validate_atomic_write_op_size() for this purpose. Userspace expects an atomic write which is of invalid size to be rejected with -EINVAL, so add BLK_STS_INVAL for this. Also use BLK_STS_INVAL for when a BIO needs to be split, as this should mean an invalid size BIO. Flag REQ_ATOMIC is used for indicating an atomic write. Co-developed-by: Himanshu Madhani Signed-off-by: Himanshu Madhani Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Keith Busch --- Documentation/ABI/stable/sysfs-block | 53 +++++++++++++++++ block/blk-core.c | 19 ++++++ block/blk-merge.c | 50 ++++++++++++++-- block/blk-settings.c | 88 ++++++++++++++++++++++++++++ block/blk-sysfs.c | 33 +++++++++++ block/blk.h | 3 + include/linux/blk_types.h | 8 ++- include/linux/blkdev.h | 55 +++++++++++++++++ 8 files changed, 304 insertions(+), 5 deletions(-) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 831f19a32e08..cea8856f798d 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -21,6 +21,59 @@ Description: device is offset from the internal allocation unit's natural alignment. +What: /sys/block//atomic_write_max_bytes +Date: February 2024 +Contact: Himanshu Madhani +Description: + [RO] This parameter specifies the maximum atomic write + size reported by the device. This parameter is relevant + for merging of writes, where a merged atomic write + operation must not exceed this number of bytes. + This parameter may be greater than the value in + atomic_write_unit_max_bytes as + atomic_write_unit_max_bytes will be rounded down to a + power-of-two and atomic_write_unit_max_bytes may also be + limited by some other queue limits, such as max_segments. + This parameter - along with atomic_write_unit_min_bytes + and atomic_write_unit_max_bytes - will not be larger than + max_hw_sectors_kb, but may be larger than max_sectors_kb. + + +What: /sys/block//atomic_write_unit_min_bytes +Date: February 2024 +Contact: Himanshu Madhani +Description: + [RO] This parameter specifies the smallest block which can + be written atomically with an atomic write operation. All + atomic write operations must begin at a + atomic_write_unit_min boundary and must be multiples of + atomic_write_unit_min. This value must be a power-of-two. + + +What: /sys/block//atomic_write_unit_max_bytes +Date: February 2024 +Contact: Himanshu Madhani +Description: + [RO] This parameter defines the largest block which can be + written atomically with an atomic write operation. This + value must be a multiple of atomic_write_unit_min and must + be a power-of-two. This value will not be larger than + atomic_write_max_bytes. + + +What: /sys/block//atomic_write_boundary_bytes +Date: February 2024 +Contact: Himanshu Madhani +Description: + [RO] A device may need to internally split an atomic write I/O + which straddles a given logical block address boundary. This + parameter specifies the size in bytes of the atomic boundary if + one is reported by the device. This value must be a + power-of-two and at least the size as in + atomic_write_unit_max_bytes. + Any attempt to merge atomic write I/Os must not result in a + merged I/O which crosses this boundary (if any). + What: /sys/block//diskseq Date: February 2021 diff --git a/block/blk-core.c b/block/blk-core.c index 8d9fbd353fc7..6fc1a5a1980d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -174,6 +174,8 @@ static const struct { /* Command duration limit device-side timeout */ [BLK_STS_DURATION_LIMIT] = { -ETIME, "duration limit exceeded" }, + [BLK_STS_INVAL] = { -EINVAL, "invalid" }, + /* everything else not covered above: */ [BLK_STS_IOERR] = { -EIO, "I/O" }, }; @@ -739,6 +741,18 @@ void submit_bio_noacct_nocheck(struct bio *bio) __submit_bio_noacct(bio); } +static blk_status_t blk_validate_atomic_write_op_size(struct request_queue *q, + struct bio *bio) +{ + if (bio->bi_iter.bi_size > queue_atomic_write_unit_max_bytes(q)) + return BLK_STS_INVAL; + + if (bio->bi_iter.bi_size % queue_atomic_write_unit_min_bytes(q)) + return BLK_STS_INVAL; + + return BLK_STS_OK; +} + /** * submit_bio_noacct - re-submit a bio to the block device layer for I/O * @bio: The bio describing the location in memory and on the device. @@ -797,6 +811,11 @@ void submit_bio_noacct(struct bio *bio) switch (bio_op(bio)) { case REQ_OP_READ: case REQ_OP_WRITE: + if (bio->bi_opf & REQ_ATOMIC) { + status = blk_validate_atomic_write_op_size(q, bio); + if (status != BLK_STS_OK) + goto end_io; + } break; case REQ_OP_FLUSH: /* diff --git a/block/blk-merge.c b/block/blk-merge.c index 68969e27c831..cff20bcc0252 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -154,8 +154,16 @@ static struct bio *bio_split_write_zeroes(struct bio *bio, return bio_split(bio, lim->max_write_zeroes_sectors, GFP_NOIO, bs); } -static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim) +static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim, + bool is_atomic) { + /* + * chunk_sectors must be a multiple of atomic_write_boundary_sectors if + * both non-zero. + */ + if (is_atomic && lim->atomic_write_boundary_sectors) + return lim->atomic_write_boundary_sectors; + return lim->chunk_sectors; } @@ -172,8 +180,18 @@ static inline unsigned get_max_io_size(struct bio *bio, { unsigned pbs = lim->physical_block_size >> SECTOR_SHIFT; unsigned lbs = lim->logical_block_size >> SECTOR_SHIFT; - unsigned boundary_sectors = blk_boundary_sectors(lim); - unsigned max_sectors = lim->max_sectors, start, end; + bool is_atomic = bio->bi_opf & REQ_ATOMIC; + unsigned boundary_sectors = blk_boundary_sectors(lim, is_atomic); + unsigned max_sectors, start, end; + + /* + * We ignore lim->max_sectors for atomic writes because it may less + * than the actual bio size, which we cannot tolerate. + */ + if (is_atomic) + max_sectors = lim->atomic_write_max_sectors; + else + max_sectors = lim->max_sectors; if (boundary_sectors) { max_sectors = min(max_sectors, @@ -311,6 +329,11 @@ struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, *segs = nsegs; return NULL; split: + if (bio->bi_opf & REQ_ATOMIC) { + bio->bi_status = BLK_STS_INVAL; + bio_endio(bio); + return ERR_PTR(-EINVAL); + } /* * We can't sanely support splitting for a REQ_NOWAIT bio. End it * with EAGAIN if splitting is required and return an error pointer. @@ -596,11 +619,12 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq, struct request_queue *q = rq->q; struct queue_limits *lim = &q->limits; unsigned int max_sectors, boundary_sectors; + bool is_atomic = rq->cmd_flags & REQ_ATOMIC; if (blk_rq_is_passthrough(rq)) return q->limits.max_hw_sectors; - boundary_sectors = blk_boundary_sectors(lim); + boundary_sectors = blk_boundary_sectors(lim, is_atomic); max_sectors = blk_queue_get_max_sectors(rq); if (!boundary_sectors || @@ -806,6 +830,18 @@ static enum elv_merge blk_try_req_merge(struct request *req, return ELEVATOR_NO_MERGE; } +static bool blk_atomic_write_mergeable_rq_bio(struct request *rq, + struct bio *bio) +{ + return (rq->cmd_flags & REQ_ATOMIC) == (bio->bi_opf & REQ_ATOMIC); +} + +static bool blk_atomic_write_mergeable_rqs(struct request *rq, + struct request *next) +{ + return (rq->cmd_flags & REQ_ATOMIC) == (next->cmd_flags & REQ_ATOMIC); +} + /* * For non-mq, this has to be called with the request spinlock acquired. * For mq with scheduling, the appropriate queue wide lock should be held. @@ -829,6 +865,9 @@ static struct request *attempt_merge(struct request_queue *q, if (req->ioprio != next->ioprio) return NULL; + if (!blk_atomic_write_mergeable_rqs(req, next)) + return NULL; + /* * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn @@ -960,6 +999,9 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (rq->ioprio != bio_prio(bio)) return false; + if (blk_atomic_write_mergeable_rq_bio(rq, bio) == false) + return false; + return true; } diff --git a/block/blk-settings.c b/block/blk-settings.c index d0e9096f93ca..45dee600d6c1 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -127,6 +127,92 @@ static int blk_validate_integrity_limits(struct queue_limits *lim) return 0; } +/* + * Returns max guaranteed bytes which we can fit in a bio. + * + * We request that an atomic_write is ITER_UBUF iov_iter (so a single vector), + * so we assume that we can fit in at least PAGE_SIZE in a segment, apart from + * the first and last segments. + */ +static +unsigned int blk_queue_max_guaranteed_bio(struct queue_limits *lim) +{ + unsigned int max_segments = min(BIO_MAX_VECS, lim->max_segments); + unsigned int length; + + length = min(max_segments, 2) * lim->logical_block_size; + if (max_segments > 2) + length += (max_segments - 2) * PAGE_SIZE; + + return length; +} + +static void blk_atomic_writes_update_limits(struct queue_limits *lim) +{ + unsigned int unit_limit = min(lim->max_hw_sectors << SECTOR_SHIFT, + blk_queue_max_guaranteed_bio(lim)); + + unit_limit = rounddown_pow_of_two(unit_limit); + + lim->atomic_write_max_sectors = + min(lim->atomic_write_hw_max >> SECTOR_SHIFT, + lim->max_hw_sectors); + lim->atomic_write_unit_min = + min(lim->atomic_write_hw_unit_min, unit_limit); + lim->atomic_write_unit_max = + min(lim->atomic_write_hw_unit_max, unit_limit); + lim->atomic_write_boundary_sectors = + lim->atomic_write_hw_boundary >> SECTOR_SHIFT; +} + +static void blk_validate_atomic_write_limits(struct queue_limits *lim) +{ + unsigned int chunk_sectors = lim->chunk_sectors; + unsigned int boundary_sectors; + + if (!lim->atomic_write_hw_max) + goto unsupported; + + boundary_sectors = lim->atomic_write_hw_boundary >> SECTOR_SHIFT; + + if (boundary_sectors) { + /* + * A feature of boundary support is that it disallows bios to + * be merged which would result in a merged request which + * crosses either a chunk sector or atomic write HW boundary, + * even though chunk sectors may be just set for performance. + * For simplicity, disallow atomic writes for a chunk sector + * which is non-zero and smaller than atomic write HW boundary. + * Furthermore, chunk sectors must be a multiple of atomic + * write HW boundary. Otherwise boundary support becomes + * complicated. + * Devices which do not conform to these rules can be dealt + * with if and when they show up. + */ + if (WARN_ON_ONCE(do_div(chunk_sectors, boundary_sectors))) + goto unsupported; + + /* + * The boundary size just needs to be a multiple of unit_max + * (and not necessarily a power-of-2), so this following check + * could be relaxed in future. + * Furthermore, if needed, unit_max could even be reduced so + * that it is compliant with a !power-of-2 boundary. + */ + if (!is_power_of_2(boundary_sectors)) + goto unsupported; + } + + blk_atomic_writes_update_limits(lim); + return; + +unsupported: + lim->atomic_write_max_sectors = 0; + lim->atomic_write_boundary_sectors = 0; + lim->atomic_write_unit_min = 0; + lim->atomic_write_unit_max = 0; +} + /* * Check that the limits in lim are valid, initialize defaults for unset * values, and cap values based on others where needed. @@ -264,6 +350,8 @@ static int blk_validate_limits(struct queue_limits *lim) if (!(lim->features & BLK_FEAT_WRITE_CACHE)) lim->features &= ~BLK_FEAT_FUA; + blk_validate_atomic_write_limits(lim); + err = blk_validate_integrity_limits(lim); if (err) return err; diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index da4e96d686f9..1e1f5016b43e 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -118,6 +118,30 @@ static ssize_t queue_max_discard_segments_show(struct request_queue *q, return queue_var_show(queue_max_discard_segments(q), page); } +static ssize_t queue_atomic_write_max_bytes_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_max_bytes(q), page); +} + +static ssize_t queue_atomic_write_boundary_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_boundary_bytes(q), page); +} + +static ssize_t queue_atomic_write_unit_min_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_min_bytes(q), page); +} + +static ssize_t queue_atomic_write_unit_max_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_max_bytes(q), page); +} + static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) { return queue_var_show(q->limits.max_integrity_segments, page); @@ -505,6 +529,11 @@ QUEUE_RO_ENTRY(queue_discard_max_hw, "discard_max_hw_bytes"); QUEUE_RW_ENTRY(queue_discard_max, "discard_max_bytes"); QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); +QUEUE_RO_ENTRY(queue_atomic_write_max_bytes, "atomic_write_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_boundary, "atomic_write_boundary_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_max, "atomic_write_unit_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_min, "atomic_write_unit_min_bytes"); + QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); @@ -626,6 +655,10 @@ static struct attribute *queue_attrs[] = { &queue_discard_max_entry.attr, &queue_discard_max_hw_entry.attr, &queue_discard_zeroes_data_entry.attr, + &queue_atomic_write_max_bytes_entry.attr, + &queue_atomic_write_boundary_entry.attr, + &queue_atomic_write_unit_min_entry.attr, + &queue_atomic_write_unit_max_entry.attr, &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_zone_append_max_entry.attr, diff --git a/block/blk.h b/block/blk.h index 20c5718815e2..d0a986d8ee50 100644 --- a/block/blk.h +++ b/block/blk.h @@ -194,6 +194,9 @@ static inline unsigned int blk_queue_get_max_sectors(struct request *rq) if (unlikely(op == REQ_OP_WRITE_ZEROES)) return q->limits.max_write_zeroes_sectors; + if (rq->cmd_flags & REQ_ATOMIC) + return q->limits.atomic_write_max_sectors; + return q->limits.max_sectors; } diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 781c4500491b..632edd71f8c6 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -162,6 +162,11 @@ typedef u16 blk_short_t; */ #define BLK_STS_DURATION_LIMIT ((__force blk_status_t)17) +/* + * Invalid size or alignment. + */ +#define BLK_STS_INVAL ((__force blk_status_t)19) + /** * blk_path_error - returns true if error may be path related * @error: status the request was completed with @@ -370,7 +375,7 @@ enum req_flag_bits { __REQ_SWAP, /* swap I/O */ __REQ_DRV, /* for driver use */ __REQ_FS_PRIVATE, /* for file system (submitter) use */ - + __REQ_ATOMIC, /* for atomic write operations */ /* * Command specific flags, keep last: */ @@ -402,6 +407,7 @@ enum req_flag_bits { #define REQ_SWAP (__force blk_opf_t)(1ULL << __REQ_SWAP) #define REQ_DRV (__force blk_opf_t)(1ULL << __REQ_DRV) #define REQ_FS_PRIVATE (__force blk_opf_t)(1ULL << __REQ_FS_PRIVATE) +#define REQ_ATOMIC (__force blk_opf_t)(1ULL << __REQ_ATOMIC) #define REQ_NOUNMAP (__force blk_opf_t)(1ULL << __REQ_NOUNMAP) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 4ff5886d3ca4..c0a5a061f8b9 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -379,6 +379,16 @@ struct queue_limits { unsigned int discard_alignment; unsigned int zone_write_granularity; + /* atomic write limits */ + unsigned int atomic_write_hw_max; + unsigned int atomic_write_max_sectors; + unsigned int atomic_write_hw_boundary; + unsigned int atomic_write_boundary_sectors; + unsigned int atomic_write_hw_unit_min; + unsigned int atomic_write_unit_min; + unsigned int atomic_write_hw_unit_max; + unsigned int atomic_write_unit_max; + unsigned short max_segments; unsigned short max_integrity_segments; unsigned short max_discard_segments; @@ -1409,6 +1419,30 @@ static inline int queue_dma_alignment(const struct request_queue *q) return q ? q->limits.dma_alignment : 511; } +static inline unsigned int +queue_atomic_write_unit_max_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_max; +} + +static inline unsigned int +queue_atomic_write_unit_min_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_min; +} + +static inline unsigned int +queue_atomic_write_boundary_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_boundary_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_max_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_max_sectors << SECTOR_SHIFT; +} + static inline unsigned int bdev_dma_alignment(struct block_device *bdev) { return queue_dma_alignment(bdev_get_queue(bdev)); @@ -1650,6 +1684,27 @@ struct io_comp_batch { void (*complete)(struct io_comp_batch *); }; +static inline bool bdev_can_atomic_write(struct block_device *bdev) +{ + struct request_queue *bd_queue = bdev->bd_queue; + struct queue_limits *limits = &bd_queue->limits; + + if (!limits->atomic_write_unit_min) + return false; + + if (bdev_is_partition(bdev)) { + sector_t bd_start_sect = bdev->bd_start_sect; + unsigned int alignment = + max(limits->atomic_write_unit_min, + limits->atomic_write_hw_boundary); + + if (!IS_ALIGNED(bd_start_sect, alignment >> SECTOR_SHIFT)) + return false; + } + + return true; +} + #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } #endif /* _LINUX_BLKDEV_H */ From patchwork Thu Jun 20 12:53:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705371 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 D33731AD9E8; Thu, 20 Jun 2024 12:55:05 +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=1718888107; cv=fail; b=kaNKa2NI5MYr5yJ/Lu3laHDhr31OCHSEcjRhgdMbHkilAf+txizSiU1GXzSFyMS2kHgOVHLU/6gqKdv9y+PUKZwEGfMlhbM/+NR7WppmmAd4DAsCKHFRzioHCBS/F8qePhsMAxbQzulo71hd9z/elQoNvREZ63pZFkX9oFWbOMM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888107; c=relaxed/simple; bh=XdNb9+NWtHcWOwBUHldwOEbxsQY4ezK5KAQlud9Tbvo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=S2r02FUjic1OEea/+3E5Cm68C+KPpf+DSQo3ZMkwOwS6uyIUepErZ3AeBhT2je2r3BpsYtvIx4k4kClnJ97dBAjntC1qYC6pXOP6zZ+NDwa487ZrQRYUF9jZ252uf8gT9fW4EpJTzPohyEXQUHMD9Rqab328Li7k5ZPWH7S1YrA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=n5Htz0P3; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=NMoPTl8D; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="n5Htz0P3"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="NMoPTl8D" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FMok004140; Thu, 20 Jun 2024 12:54:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=VAoiYrEgQ/W8Jzh+zBX7f+UGG9sXdcgI4ZPcNCD9etA=; b= n5Htz0P3gLjMPR1EXS4lqquDRUSMp3k+no91CQpppFAVf0I7xhMiKPg/B/mQbMpK EP98Rl5qCjkz3jey0WVP4IOXP4xADqLGQEtbDKWn3q+Xe4NPnHl/R8cr7qBTbqwe 87/ZLdBbAHaoOPqap/60q1yY42Hw4myI+i1cxM1rhULuB7ifLrFwuAYJg56+X7al J7E8xz15hJ8TEfDZtya8xhnICJ5uzRzTq3MZ4igWGKGftpwdIdbl/oD+in5Nlys0 u4pIXpj9fcajfa4gYiQ9OScm+dfKf1WkjSEtbL1CJ+bTg6zKO4DD6aI9eG2iLR7h cQQthKJKSUXm9huusBBbSQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9nb3mn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:36 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KCbFx1032811; Thu, 20 Jun 2024 12:54:35 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2040.outbound.protection.outlook.com [104.47.56.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dae6hc-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AJwzptt1rAK0dfz3KDQijqp+UxBOu9QdAz4TIW3HS7lfR4m81Ud8uRevOj34oOFjTgB+tIRnK7/LreQakiyB1KL+EEciVC7MODpzWQyx4YGX5AC9n6EFqel4vdanH5tO3+hg6z9DA6JfbJ+B1rNryjuegvkGXxyCBLGNoSqyBdxOpltn5iIPUH7xv6we/7HBWTqTExKtSbVTNQMhHzFgPIZ32keVpEwdtC7zDkJ8wWCAPysD8VQbAAVyvqmmZLSs/zvHAfRu0OwcSjJyKbujKpii6yjPigNO//YppaZlrodcE3RCdTHMYy1Tn+WOasPKUxVq0VRSK3bLeE8rsGnK2w== 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=VAoiYrEgQ/W8Jzh+zBX7f+UGG9sXdcgI4ZPcNCD9etA=; b=FSgChU8nVjtfTVkWGiNlA8OA/4Q1uRU//HFlvACv9PK6N4i8abdOGv8EMLj+54SnOiJbfOAhqBeQwmhXZXH6Bs1c6BW6QRtRShkUHqVKxc6RyujqdQXaWnQ3KsdeLduNKSm02F0hX41WX44iOkwmM+/FziClZsGTonCtcfllZSA+/UdxY36mwmzwmo4L4X7thKJcenl81YLKxFVf8VpxG3Dckh5ks7tPtnlXQniTGSWwuTvXa3thfT7UyCv/fGjhBNSUSs4POIKK006+2pn55eWIwRfq8XGWTAL1PrsIZLmum0g6Xy88zyHpfJiFNJUqxZ3oen5y13JU5PPGKBueiQ== 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=VAoiYrEgQ/W8Jzh+zBX7f+UGG9sXdcgI4ZPcNCD9etA=; b=NMoPTl8DBmrGqT/wOmi6Ri8LUWYyCS/LQJ1M3i8dKsWFC6StzWoqralG/65MHg5BdaFW9/eq1ZlHD3/YS6L8YyztANewx5GjFgHqI0yqA+/8AJGNpY5lFvlr+UE2Y1vEfbd828caEYXlhEwr65zLOySaSJ5vrBle3xoLaRppmOQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:33 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:33 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, Prasad Singamsetty , John Garry Subject: [Patch v9 06/10] block: Add atomic write support for statx Date: Thu, 20 Jun 2024 12:53:55 +0000 Message-Id: <20240620125359.2684798-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL0PR1501CA0029.namprd15.prod.outlook.com (2603:10b6:207:17::42) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: 34c998f6-9695-46fb-4f64-08dc912821cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: OgMMPEHeCtJ/wy+/J6D+pXLmU2Agafk66lKljmCi/i8VygBEIe6r292ZxbLVEPT7y0rjuothZSCvB1o6OI4s6xYJ2XgqXq6Gvkqt055fhRZu9S4b5+4tNPcO7FOHVKRSH6OvNOlR0FzFFUDPyDnm1g2hr/P91vCiCgni/aa4rxsKQo5gKg4kk8+ZN6xZV7HtPhahf54/0hGuXnYzQAgIbuVs+n2XAX5Lz9cIiPdTDNHJILDZcBG7gRxafKp1gw/A9bSLUS9uCTUigFBUwKOEKY201ikH+99596tdSPgZKmzSW77M7l2JhIe+dtJ2OM71ZsvQ9DGx4sgqO+9M+udk7qedMsL44qp/9u3+Cexl6HXaSOBCIaAJLNg96A8Z64eGxvDrcPAkKkvaA547oYRBsFzUOD6DPwY44xnOExcRmN5VbukO7Z6ZXUt8AFx1g25R04mT8MwBxSZWENe748evQGj8pYHUXDhOFbzzkPXNt9Gd2F+qn8S1VJWZCekLcvP5uEADJYCtRbk3R2mtSOlJ2sBvz4nIj6VTXQUkv0VyGH3+U49L/2gxQQRlTg3cpEKFHVyCHrXLNuH0QPJVHNBgr+jhyFeZrEjFeSBVT+tsQfTZQWMYfyWhuvFhwkSz+V9oiynVS1iBWf89gnspVQey1mzAmV/ISoPiQo9aGKVW2hNtU7laWg0cvlC5+i8DE4rXRWG55aCBGyv3u4BzVH2/JixwNrm+2B/XhQ6BkIs/das0zB0cHuLpVEQmO+mzfjzVGuvQSD+8XwQI0wyLu9xxNxWOR0aADNR/wxKh5I2Ncz/6wXHJkedXbIhGO6BKtw9frmCxU40c/fMO+vb2j7AB+ensKREMESo9uVoJMuAFTN40sx/xyE79IMZdCRgINfZiHfJ9JiclDzY+Gjy/x3tt2dEtphYwCfieE6DUE0Z5jmenB9IyfdEsMeUn9DHUnmeO9dME55n9FB+RlkZmsG5Plr83ZU5zcKpgZmPquzr8eo+wU+uphQocdftjI1kYKzSoUPYtLEyjmr2Chtz05GxxwjpQKNv000QdpAG+DJCxWbrulDqcCiKi7wl6TyQpgLQIbiG6uRcwn1t1j+E+UkCbMmAXZLTvcHQMujpz44RngNouD8jqgqmMz4grjXIwQBB7houPahTplQMIFqkcV/hchpZvNzbDV2hxnYg+wWhf07swXAo5iP9Y2GJwLM78S3w74DgX7lvXUhmHgPueA1Eq1tkuOXF5VeZXG/LJyGO3D2RV6T37s65bNsWBc+3HU29J5zNLI32Hw6plGvQw+/L/ibzqpnZCrjYiJwm07CAfLpfYIuCuihvC1qE+cY8cCUQzCw/JoDolb1Hw050JLXT4pIsE7RhOO+TW0/39Il5myjg= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: btFNfDaTmR2jgPEpFEBIG3nmknroVfbqWdiNo8XPYE48pBLzdOrX0rEv28PlwIz5163veGOemgHhRpIRpqzA1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6Vf/KtXITCLuJSFlKV6U9i8RQ/5hUw6QXS7uDTK3/JGb/5wh6J15co2WritQTNTYorAjajapgbEHBDf5g1OL4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 34c998f6-9695-46fb-4f64-08dc912821cd X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:33.2759 (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: aNMs1bEDEjRhqrEr2tTDJXoaQ6q0838J/bxgQQLkL9hCTg2J7AjJi7pll6z97RSGzLWt6klazwDoF6HGeLCn9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-GUID: eUOhF0qUruTfs8oyDCSGQpmSDGNgmpm5 X-Proofpoint-ORIG-GUID: eUOhF0qUruTfs8oyDCSGQpmSDGNgmpm5 From: Prasad Singamsetty Extend statx system call to return additional info for atomic write support support if the specified file is a block device. Reviewed-by: Martin K. Petersen Signed-off-by: Prasad Singamsetty Signed-off-by: John Garry Reviewed-by: Keith Busch Reviewed-by: Hannes Reinecke --- block/bdev.c | 36 ++++++++++++++++++++++++++---------- fs/stat.c | 16 +++++++++------- include/linux/blkdev.h | 6 ++++-- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 353677ac49b3..3976a652fcc7 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1260,23 +1260,39 @@ void sync_bdevs(bool wait) } /* - * Handle STATX_DIOALIGN for block devices. - * - * Note that the inode passed to this is the inode of a block device node file, - * not the block device's internal inode. Therefore it is *not* valid to use - * I_BDEV() here; the block device has to be looked up by i_rdev instead. + * Handle STATX_{DIOALIGN, WRITE_ATOMIC} for block devices. */ -void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) +void bdev_statx(struct inode *backing_inode, struct kstat *stat, + u32 request_mask) { struct block_device *bdev; - bdev = blkdev_get_no_open(inode->i_rdev); + if (!(request_mask & (STATX_DIOALIGN | STATX_WRITE_ATOMIC))) + return; + + /* + * Note that backing_inode is the inode of a block device node file, + * not the block device's internal inode. Therefore it is *not* valid + * to use I_BDEV() here; the block device has to be looked up by i_rdev + * instead. + */ + bdev = blkdev_get_no_open(backing_inode->i_rdev); if (!bdev) return; - stat->dio_mem_align = bdev_dma_alignment(bdev) + 1; - stat->dio_offset_align = bdev_logical_block_size(bdev); - stat->result_mask |= STATX_DIOALIGN; + if (request_mask & STATX_DIOALIGN) { + stat->dio_mem_align = bdev_dma_alignment(bdev) + 1; + stat->dio_offset_align = bdev_logical_block_size(bdev); + stat->result_mask |= STATX_DIOALIGN; + } + + if (request_mask & STATX_WRITE_ATOMIC && bdev_can_atomic_write(bdev)) { + struct request_queue *bd_queue = bdev->bd_queue; + + generic_fill_statx_atomic_writes(stat, + queue_atomic_write_unit_min_bytes(bd_queue), + queue_atomic_write_unit_max_bytes(bd_queue)); + } blkdev_put_no_open(bdev); } diff --git a/fs/stat.c b/fs/stat.c index 72d0e6357b91..bd0698dfd7b3 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -265,6 +265,7 @@ static int vfs_statx(int dfd, struct filename *filename, int flags, { struct path path; unsigned int lookup_flags = getname_statx_lookup_flags(flags); + struct inode *backing_inode; int error; if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_EMPTY_PATH | @@ -290,13 +291,14 @@ static int vfs_statx(int dfd, struct filename *filename, int flags, stat->attributes |= STATX_ATTR_MOUNT_ROOT; stat->attributes_mask |= STATX_ATTR_MOUNT_ROOT; - /* Handle STATX_DIOALIGN for block devices. */ - if (request_mask & STATX_DIOALIGN) { - struct inode *inode = d_backing_inode(path.dentry); - - if (S_ISBLK(inode->i_mode)) - bdev_statx_dioalign(inode, stat); - } + /* + * If this is a block device inode, override the filesystem + * attributes with the block device specific parameters that need to be + * obtained from the bdev backing inode. + */ + backing_inode = d_backing_inode(path.dentry); + if (S_ISBLK(backing_inode->i_mode)) + bdev_statx(backing_inode, stat, request_mask); path_put(&path); if (retry_estale(error, lookup_flags)) { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c0a5a061f8b9..5e024b2b1311 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1644,7 +1644,8 @@ int sync_blockdev(struct block_device *bdev); int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend); int sync_blockdev_nowait(struct block_device *bdev); void sync_bdevs(bool wait); -void bdev_statx_dioalign(struct inode *inode, struct kstat *stat); +void bdev_statx(struct inode *backing_inode, struct kstat *stat, + u32 request_mask); void printk_all_partitions(void); int __init early_lookup_bdev(const char *pathname, dev_t *dev); #else @@ -1662,7 +1663,8 @@ static inline int sync_blockdev_nowait(struct block_device *bdev) static inline void sync_bdevs(bool wait) { } -static inline void bdev_statx_dioalign(struct inode *inode, struct kstat *stat) +static inline void bdev_statx(struct inode *backing_inode, struct kstat *stat, + u32 request_mask) { } static inline void printk_all_partitions(void) From patchwork Thu Jun 20 12:53:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705373 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 EE2511AE85C; Thu, 20 Jun 2024 12:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888110; cv=fail; b=FRI569PKouSmq9P/ofdS5OgJk992/WmIknsLZV49lDRwQqwVWig6AtTf9YQgledqT8Ns8690eRSHh522tSqFr/Z82ociZSo6hhGGzcqewzjSyinwRfpHWURY9x3sESgEszfgUXQCVyiovZbS4MrPursJKNuTgpzWIvssFNHrY0o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888110; c=relaxed/simple; bh=ftZ6f1r38ryoe1kq99PhyTkR16LpBz0DXyC9/QcgzD0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=PSMq3nh1qCoaaiOVZxVFqHTmfRpA2Na8FqNBMe3+dWkS7MTA9qeijFA1t+NA3SHMnduYhdxkYsENySomLvRqnJM5oUdMrojpGeMPNTYzgxivLf0tgCEclXh//6uAaXwwx1rc/vZiRwgPLctXnteR1FeAXUtUQxy4B4dmP5dOXck= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=FJ8o0SxO; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=Oxq0luYp; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FJ8o0SxO"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="Oxq0luYp" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FTrN002262; Thu, 20 Jun 2024 12:54:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=CNSOjZF84UFsx4hF5jDDwIFhmDDOPLzERuihDLak5GI=; b= FJ8o0SxO5dXwHBXkyiiPmCvUeFEFeKR2i+hcze33/vxOzYXEyZhqB5w1Cg/glfi+ oCYufyoTDNBeKh7Erj26fU/RfHb0B3aq5NnxyoE/FsQc4KmsjE+3faKAh2p+5EAr gf42EzfLBmG/nixuJrTlIM3TMKhcyde8D+GrMefnacoDrGuOWNZkOGYX25r6PVJM 7dbcVPYnEYmbtIqFkGLt05UNHWe/+SGr+GWsu9N6iv15HTzc89fqFT+Qwpy+GOgg GkbDPduO1t2QA+PPOix0zRZmGqVaMBg06YmWrGboYV43HpMZHZ5NAtMpck1/tVNV 0q0nBLT5WdC5zEGh7cH6cQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9r34gv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KC2M1v034751; Thu, 20 Jun 2024 12:54:37 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2040.outbound.protection.outlook.com [104.47.56.40]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dap46t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JPA4qor1TE3ZGhQn+gt9ekyaOVYGNQQYE5AT936iusCG6Vg57CMQ3NzKtosD4lv3GxusF2hbvSWuEsYsd3aYazJDmubAAJqJ9vSfeIuzbLR1WAS0bW7vZiNWe7f/WQp8OaY3vw8eq2X+9nXLYzjnqIhcAoaDEYKugtKX9VPhI8vvVvDObhU9TuP2UbIpsJTRwhvYTBiHRYdykbaiTAPZiaAwn3ELVG3f23AZrCPbZTJ9G2VEf92bERNsUjbIuNPN765Y/6k9dM3K1+Bkyv5f2PSqVB6x0eu41xLEl7HyVlNXvPxKgu4ehnxZV2o954iiKpEnxhOCH/cig2If2+LgNQ== 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=CNSOjZF84UFsx4hF5jDDwIFhmDDOPLzERuihDLak5GI=; b=iEqfnCIjfo3q/0pMN0Zql02hUI4EqGOwQvDAjFBfYrfyOe1rgvO0Jui7+xheetaRwc1CzpCbtdt2ODv4zyvxfrWVOAhvgHF2AKnhUT7QXSfrXYZ93NKXFYkLeTcGrKlvhVJfHh+3M1xBBJzCiuIDcUPmR/SlpQuQvnA7GToxAQzMzlX2YIT/4neTYpgpA2fBY75gZ8eK05rR4Unwur+LHjBhB/lYrloi79tzfMIore2XbZrEt6i+NhbER2TLTSyXglWnWLO5qRrdvrbf+qmqQkFZ/Ks91cFzIdXsovMzwlPRIeJkyzUYcUQtb7xxD5XX9XJf8sYlpcrwrbN5JzfeXw== 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=CNSOjZF84UFsx4hF5jDDwIFhmDDOPLzERuihDLak5GI=; b=Oxq0luYpB2IwHroyNEGNPLs463M7OGNmLzHGxAVcRXwLS7xuMoAoME4JNoXbu/NUV3ffZQax+DJsp05s+ZNn6+/HGQedszdl25cVy1Cbt0CmNHlQsra370DDNGYbfvre4gzBNOA15IB7J+2BQWMLSjZIVzqAje4pAMxmI61rIy0= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:34 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:34 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, John Garry Subject: [Patch v9 07/10] block: Add fops atomic write support Date: Thu, 20 Jun 2024 12:53:56 +0000 Message-Id: <20240620125359.2684798-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0042.namprd03.prod.outlook.com (2603:10b6:208:32d::17) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: cf398931-1ff3-4b6e-3194-08dc91282295 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: ks4momK4XuKL1S+xPs83twmwqVqf41MVW3m1+olbfKB8WBNCDv60fwGLXCRow+aRPOprD5G654p3J39rdH9jNtpOqcmAormVU0wcK7OS8JPvRbiguWbUK1M+JlCVJpzojUxMOBjcNX5QzyAACOl5teF0N8pGvIVC/Mu7n0SdJC+jyTv/Z3KdOqAUkojKUOUi7fbvMWfjcLuwpZU9O6OSRBHk9mJc5gLcJSPu6Z1TWd3ECjFBxcO0JwlCRlwf05rzdGid7yRj4hgaop5Mvndl6Ibub4U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mtxJvGGzYxjlpvneYcoow3j7+6lsrNs= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qyGnuDXHUrllO1U04ZYNhwFRIQgWK4uwdldZVJOSW7CBylU/IDRBjO/doxe9HnxwjQUZ2BhP/WO8ETYOnkne7kws9m4u/TmcBgZTSxDS2d735gZM3KnnZ9LYYambs0NT3zZQrgv3nwPNTZmihRccm2Ag51w4k+XPPF0pregNqKpJExz3Y91xZUymD0+VvFrWUKia/5qkfi1Dst+IVQczuIsw5BArjEkYcIjR4w8wFrdOq4sVShNTu+CkZqHn3sV2qK0m8lM4Qy0hFEKoERMKgJAZNJaRPmqGhgceD0+WoX6HzovZQmi8U3KWg5waWRdcOmCwId91yVkxXA2Qzv7QFr8ZekF5RelirUExZhSTXw6FiiYvEnBGzi4mcYIgmbBK521iZJVM2uZD5V2+dHT5VebskGdvgldIMn1OrshQuzlXZIOxqJ5BMv+yxZKmk/1SKQ0iEQI1vwMNfqJ2DrTmhpJf+TbE0f+9imC/vQy2fgnjPwxl65wSPI5lPqZNdpBGpQVRfSMZrfLDuAiYTOaO1ee3btspkl/O3i6q0sdG1iIYfpcpbfQQga/iW8v3AzW/xi8K7Ly1wg02g7dQct2/e0vEJXwP7UhNYubTtUOqClxjUKO9M4xSSE55GfihbUWxIy6BF9uWdFDRpIPAHlgwyRYtho9Lut0fSsAKIo227ASqbUdOt4eRGHKGeoDWmusQXLPBQbFrQoEpyCSTfO2YPLMuboqxyJqkEKLg5lbcZA0rQdLoD/EwILwGRIunUUGbz25vfQ8ktYeJaPU8kmObeJxCSLHXNg6svLPPQF7mJOVSmwrZsgZtBPNUOlqikrhZ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WR3JqhUWkpUXixwysESNpcxgPscR219R2GbpPks3ma0yHRSvDSlSxf/N9e4zWWlLUbv5ntXeHshwpKPGZ9Xo2WehPhf0FVjBYdZfayqO3TQtemodnNIKuyFt/r8Auq765mGoftSWr2GmcS0E3tsGTMbDSk4DaE2CtOnTe2EPF0KwOVJSy6avD025u9EPLtY8BEiKxz1rWPFvJUEgtuOGFZWIagfoWasZo42Wcjz9wpvpbuD9IUN1uThSyQvAGc6d89g4OfMlZTjL+Lll3/V5GC6zMps9i1n3FgVisLnEV/fnryhqrA1nO4lcuXKD2NAr5/DYYDwqtG11Pa/S7OsffWTizmpWe5u+1+zGp9l41HgiWGntCSOxFn5tNvLMc2TcscnberNFm995kq0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf398931-1ff3-4b6e-3194-08dc91282295 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:34.5998 (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: pBo9x3CcerkNrXrRvAGvyWqaTCdAvcbl3oYbKOtc64g20/Y3nnXnfuc48i7ajc6bW7FirCDTA/4BWdC170/QnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-GUID: a1uH6-wMwzJj73xKkqNZklMoaHtOr2DA X-Proofpoint-ORIG-GUID: a1uH6-wMwzJj73xKkqNZklMoaHtOr2DA Support atomic writes by submitting a single BIO with the REQ_ATOMIC set. It must be ensured that the atomic write adheres to its rules, like naturally aligned offset, so call blkdev_dio_invalid() -> blkdev_atomic_write_valid() [with renaming blkdev_dio_unaligned() to blkdev_dio_invalid()] for this purpose. The BIO submission path currently checks for atomic writes which are too large, so no need to check here. In blkdev_direct_IO(), if the nr_pages exceeds BIO_MAX_VECS, then we cannot produce a single BIO, so error in this case. Finally set FMODE_CAN_ATOMIC_WRITE when the bdev can support atomic writes and the associated file flag is for O_DIRECT. Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Keith Busch Reviewed-by: Kanchan Joshi --- block/fops.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/block/fops.c b/block/fops.c index 376265935714..be36c9fbd500 100644 --- a/block/fops.c +++ b/block/fops.c @@ -34,9 +34,12 @@ static blk_opf_t dio_bio_write_op(struct kiocb *iocb) return opf; } -static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, - struct iov_iter *iter) +static bool blkdev_dio_invalid(struct block_device *bdev, loff_t pos, + struct iov_iter *iter, bool is_atomic) { + if (is_atomic && !generic_atomic_write_valid(iter, pos)) + return true; + return pos & (bdev_logical_block_size(bdev) - 1) || !bdev_iter_is_aligned(bdev, iter); } @@ -72,6 +75,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio.bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; bio.bi_ioprio = iocb->ki_ioprio; + if (iocb->ki_flags & IOCB_ATOMIC) + bio.bi_opf |= REQ_ATOMIC; ret = bio_iov_iter_get_pages(&bio, iter); if (unlikely(ret)) @@ -343,6 +348,9 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, task_io_account_write(bio->bi_iter.bi_size); } + if (iocb->ki_flags & IOCB_ATOMIC) + bio->bi_opf |= REQ_ATOMIC; + if (iocb->ki_flags & IOCB_NOWAIT) bio->bi_opf |= REQ_NOWAIT; @@ -359,12 +367,13 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); + bool is_atomic = iocb->ki_flags & IOCB_ATOMIC; unsigned int nr_pages; if (!iov_iter_count(iter)) return 0; - if (blkdev_dio_unaligned(bdev, iocb->ki_pos, iter)) + if (blkdev_dio_invalid(bdev, iocb->ki_pos, iter, is_atomic)) return -EINVAL; nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1); @@ -373,6 +382,8 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) return __blkdev_direct_IO_simple(iocb, iter, bdev, nr_pages); return __blkdev_direct_IO_async(iocb, iter, bdev, nr_pages); + } else if (is_atomic) { + return -EINVAL; } return __blkdev_direct_IO(iocb, iter, bdev, bio_max_segs(nr_pages)); } @@ -612,6 +623,9 @@ static int blkdev_open(struct inode *inode, struct file *filp) if (!bdev) return -ENXIO; + if (bdev_can_atomic_write(bdev) && filp->f_flags & O_DIRECT) + filp->f_mode |= FMODE_CAN_ATOMIC_WRITE; + ret = bdev_open(bdev, mode, filp->private_data, NULL, filp); if (ret) blkdev_put_no_open(bdev); From patchwork Thu Jun 20 12:53:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705375 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 598A21AED54; Thu, 20 Jun 2024 12:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888113; cv=fail; b=Uytap/R2WC8QKQ7+egiigF9YFlc1qojxKgbv8euv+Gj6v5XsH/aHSunB6KiG72FLaGSJ+d6dIWqJJKWLjsr2F2qKUZ1L55/LMWUB/K1kvFMwMQdK1jHFaSlVyr+AaqTfK3EtYh5T10H+JgEd4ZJEaCdK3LAOWA52Wfdq6ouKM38= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888113; c=relaxed/simple; bh=8KSc8a/Rya2oJUvCyyrt8iGzudHItq+VtCAidAfLNn4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=qnBa0Npz8fZUpWpmToJyuduELSb5n4P25D3e4WjqB6oe9d4JxnoUEvCPofRvTLmFJeDdA2k+kChm8vWzEdM2NIwKFGqtLyvmXS1tXok0Lo6S1eH/OtYeOZqOHuTYXlO7WhPY7oWPMaGGfVdtva2t8amJVpBpdmX1JQG3qx4FmX0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=ZOzDPRgS; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=RhYo1New; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ZOzDPRgS"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="RhYo1New" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5FHeA018254; Thu, 20 Jun 2024 12:54:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=H995haILi1kcMMYMLd04ROHekDQAV1cD97v6pfBgazY=; b= ZOzDPRgSIwBeHZNiyYpL2YP9yzQgaPaSMm2BIWIZ02XQQxNC/7tfP1HnI/enlZoC /C3MbFr6Tb45cpuHx6Ybw3AxxlBhrQwU70ltPkpX9yRKDeXFD/or/AyUXbaxk4xv w2Xl3srLpTSqwK6YW+CDqYMiU1jVEDaNX2ODcoMg4vI6lvhW8gDdtYocCsNA3x07 XHUmsQWEaMpwEYMvrlg412y4AiwQ/L9k+dqYL2BCSkCzwpdL/WLkF+fj3PwHpTow v9KJq5m7flsKthH4tSS8PdLHY1C37TRoglKjr7yWYnqn/JSaB/kGfyA/Tegse+Ig OIDJkQc3LZx08GGOLaH+mA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yujc0b440-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:39 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KC2M1w034751; Thu, 20 Jun 2024 12:54:38 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2040.outbound.protection.outlook.com [104.47.56.40]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dap46t-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJdhZJXJ3GGbYAWGd3+3dg56DsVjjLW4ft+dDxPcPc1FtoOwQnGT0rmJbJVrqaHL50qTcT2GOlfKesZEkkLa0DTGToOFbjLX8rMz6Fbp+93Mbp9Tun7w/Gm8x7eMzvus5cROcYvGYli8bMCukQhCmZtZxu0yhRNSr628FoWYTWzpUyqrmY5dS6fPN8QGRUQoFJSFQQMx0tANxsFsxb0q/z0FXJp7kRiPtRi8aaPvRD4/3tlrILFGmTSX4uXeGd9Uq4Tkf1hlM2/TCsQ6t6gHQPLOpR8qIiZgKQHEWiK2M9wGHTUETDVn3JvrNGSOVdGZ126RdFveRHcp3UXuYyYY9g== 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=H995haILi1kcMMYMLd04ROHekDQAV1cD97v6pfBgazY=; b=UET2kLgXAahVl8nI8cOapv2BMSUXYaJUZWyf/JArSMx5afWMVIW284ovKDAT7C3o38ULA+mrOpN1YqkOuR3dGXb8li0MeX5NzrSDQ4l3nsWAcxC5TlwwWH7SMdjuOTXEOu1TQet/4tKbI+Bv7+ppvSFf6AngUksHF2cXlRk4fvZ2BGck8wtvuZFNO1uRYM0mktaIcIiMG8lHeddwK5KkG9dv6RLlBFzqrlMZ+tvAdYCNBypPgDnShEKBih/udOhYEc6PQMpXkVD83ap4U7D2scJTMzhzEirGH851ls86K2DpKfXLNic0825WH0wBwG58xeXAWo6PZ7PNV26HahW2Kg== 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=H995haILi1kcMMYMLd04ROHekDQAV1cD97v6pfBgazY=; b=RhYo1NewjyBQatT0obdomdtGcdJhSAhlgmT3KeVhRVfnty4ARTWUFe3WhIGei+gsn6euAsFW/uPeTe5YoSeop3f0UUm5jgVB6K2rBjQcaaDH87Vi6WWY/cyEA7pXf11dbLgbtv9gJgqENJpKo/8CtweSMs2+LL6AIYua3ElkTCU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:36 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:36 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, John Garry Subject: [Patch v9 08/10] scsi: sd: Atomic write support Date: Thu, 20 Jun 2024 12:53:57 +0000 Message-Id: <20240620125359.2684798-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P221CA0003.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::9) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: e8ba7b6c-c8e8-4ddd-d5bc-08dc91282383 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: 9NI5pADxDkfhzQOYYtXELt3ffPbPNBgCRiZFXDP3gsqEmvLDx/+OUYZ7R7Br6Zw+WtGW5xl2fWwcepfi352laWJ0RAmyzrFAFYGdxmLnxHhK8T2M1S1OoZBFP7927KcpN/IWpHE0HmH8RMjBycXnY/kpdUYNtUMW94Zz9CwTPNOsHXbcpX8dBiW4OSfezR7+uy0OrcTDvA3CqN1JPKqo0qYsT2QBGccqeiJKYaz30FcF56/FAYadMmXxgn82n6/7kBuaiwXv8CWWrVpQyRsV01ARbwf6bvx+gOI48vvsPxwL2XxJpjQo9nFr2KAnmyZuaNllMTU6sKT+dEZTq99pju1G2RUH8E7SP5eqxhixekK02U533MJOfkgCpz1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PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ih2o6cOknyfmEAItgq0ffiJogw/03MP8h78vJcR5piN3SZYMKS//OYIcNq1YiYsnim2jer07rjqJPCPSXXJOAH28+MtsUCJjD8IVeGlYWHWkC9tbJyc7b//ZbOmexDrCzlm5wifVHx3Qc8ze838Gorl/GT09r41qHoach0BqCj9un2CchtBvlnmW8yLcCUWNSjPTyvVZke+oyW3Z2Rw29TWmIJuyBKL5U2wgekrO0T7Y1gON6r/q6bTmVqcM5eXcSwLjst5hGqqw2LGDmDERVVQxXKdYVWaxHzgbyAyQfoy/yeQ5EDhuLAyRnkXTp27GCeHyy1aM3Bim/FsSQrUPYAM+jCY5ECZGna1sp9y1tc7aPKSefEx0F49M65q1CcqH0az5Ut4Hq19RAQHY05nKeex/YjuS8MlFqprWvryHyc7G2NmJTMF53MPkD407KVRDWF07DCM7FBkna2fcEcAbVjdlrkIsbNKOqvX3w1awx1q+b+9BKN4H4UXMYzOQQ3E4R323DLmgPohL2W2q2Cd+qq0qb8bmYMBKkEsDqNzqXedzZ20IveIv7BJSl793I3YVQUoEbB9p5cimMLueL1ffyzObKUYO12JOMP3tY04Xv5Yyyy9IcAhlmua8dSzKuvtVh75nTkfxM1YgUSwyDvpSTHz+ijbSNFAmIll8cn3J2le+ckVudl7Q2kl9b/hdN977gP2LaHrHJd4MiDAbu7FRR5Alrp6N+Oqd/Jog0+GqG+TMvcCdtoXc7PBBcy8h1RJvQUHQ6mi8U50lC3uBSidU3cUfAO3E+HBsnYMMphzyVTuqZikUsRZCGuIBqx/tCEifNDgBL8MqRIPfJwS7D/fE8CbnlFMYqafGpV2SV64KoBk3lyyNMQ/z9l1E1G1ftdB5GUEZuG+gDmnPRndugKktBhUYn3q1AJ5AtYdRTW6BdJsvyG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K1i5P3dtJMOn/UWp+20zsFeeEWQTj6wWGSGdiUscdrLFRZTNTzn2TPkkthErxCPv1O1JM2CKeq/5yqK9oUjK/luuY5UcAN/gaIhoIMQFaQq1klZYPZG0+EXkJ7MDy2XzxLe+fNtQe9qiGA1CxQ5KvFB2tcZvMU52fSpMLclI/03E+yijJBrgr2W3yolDGkWDw0zh+Ez3rAhAK8wzuwfgMaXqdeOeIZS6PPp533p2ZdCmXuLF6Zh8ebk1UL24r42ENsIS9PNuoG424xJ7ptQcx9qQsohuNyvMK+4Djs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8ba7b6c-c8e8-4ddd-d5bc-08dc91282383 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:36.1757 (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: PRF/WiHZ5B28wWsbRxy8ZPsyC2eelY33IRqMurjL8wXKWHnXeTbcKZvUtT1fbymR3BXCCnxzpz1/wpgx15SP0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-ORIG-GUID: VliTFc8u8QHrmPJ9yzQS1ioQu9ZPC5Cc X-Proofpoint-GUID: VliTFc8u8QHrmPJ9yzQS1ioQu9ZPC5Cc Support is divided into two main areas: - reading VPD pages and setting sdev request_queue limits - support WRITE ATOMIC (16) command and tracing The relevant block limits VPD page need to be read to allow the block layer request_queue atomic write limits to be set. These VPD page limits are described in sbc4r22 section 6.6.4 - Block limits VPD page. There are five limits of interest: - MAXIMUM ATOMIC TRANSFER LENGTH - ATOMIC ALIGNMENT - ATOMIC TRANSFER LENGTH GRANULARITY - MAXIMUM ATOMIC TRANSFER LENGTH WITH BOUNDARY - MAXIMUM ATOMIC BOUNDARY SIZE MAXIMUM ATOMIC TRANSFER LENGTH is the maximum length for a WRITE ATOMIC (16) command. It will not be greater than the device MAXIMUM TRANSFER LENGTH. ATOMIC ALIGNMENT and ATOMIC TRANSFER LENGTH GRANULARITY are the minimum alignment and length values for an atomic write in terms of logical blocks. Unlike NVMe, SCSI does not specify an LBA space boundary, but does specify a per-IO boundary granularity. The maximum boundary size is specified in MAXIMUM ATOMIC BOUNDARY SIZE. When used, this boundary value is set in the WRITE ATOMIC (16) ATOMIC BOUNDARY field - layout for the WRITE_ATOMIC_16 command can be found in sbc4r22 section 5.48. This boundary value is the granularity size at which the device may atomically write the data. A value of zero in WRITE ATOMIC (16) ATOMIC BOUNDARY field means that all data must be atomically written together. MAXIMUM ATOMIC TRANSFER LENGTH WITH BOUNDARY is the maximum atomic write length if a non-zero boundary value is set. For atomic write support, the WRITE ATOMIC (16) boundary is not of much interest, as the block layer expects each request submitted to be executed atomically. However, the SCSI spec does leave itself open to a quirky scenario where MAXIMUM ATOMIC TRANSFER LENGTH is zero, yet MAXIMUM ATOMIC TRANSFER LENGTH WITH BOUNDARY and MAXIMUM ATOMIC BOUNDARY SIZE are both non-zero. This case will be supported. To set the block layer request_queue atomic write capabilities, sanitize the VPD page limits and set limits as follows: - atomic_write_unit_min is derived from granularity and alignment values. If no granularity value is not set, use physical block size - atomic_write_unit_max is derived from MAXIMUM ATOMIC TRANSFER LENGTH. In the scenario where MAXIMUM ATOMIC TRANSFER LENGTH is zero and boundary limits are non-zero, use MAXIMUM ATOMIC BOUNDARY SIZE for atomic_write_unit_max. New flag scsi_disk.use_atomic_write_boundary is set for this scenario. - atomic_write_boundary_bytes is set to zero always SCSI also supports a WRITE ATOMIC (32) command, which is for type 2 protection enabled. This is not going to be supported now, so check for T10_PI_TYPE2_PROTECTION when setting any request_queue limits. To handle an atomic write request, add support for WRITE ATOMIC (16) command in handler sd_setup_atomic_cmnd(). Flag use_atomic_write_boundary is checked here for encoding ATOMIC BOUNDARY field. Trace info is also added for WRITE_ATOMIC_16 command. Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_trace.c | 22 +++++++++ drivers/scsi/sd.c | 93 ++++++++++++++++++++++++++++++++++++- drivers/scsi/sd.h | 8 ++++ include/scsi/scsi_proto.h | 1 + include/trace/events/scsi.h | 1 + 5 files changed, 124 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_trace.c b/drivers/scsi/scsi_trace.c index 41a950075913..3e47c4472a80 100644 --- a/drivers/scsi/scsi_trace.c +++ b/drivers/scsi/scsi_trace.c @@ -325,6 +325,26 @@ scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len) return ret; } +static const char * +scsi_trace_atomic_write16_out(struct trace_seq *p, unsigned char *cdb, int len) +{ + const char *ret = trace_seq_buffer_ptr(p); + unsigned int boundary_size; + unsigned int nr_blocks; + sector_t lba; + + lba = get_unaligned_be64(&cdb[2]); + boundary_size = get_unaligned_be16(&cdb[10]); + nr_blocks = get_unaligned_be16(&cdb[12]); + + trace_seq_printf(p, "lba=%llu txlen=%u boundary_size=%u", + lba, nr_blocks, boundary_size); + + trace_seq_putc(p, 0); + + return ret; +} + static const char * scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len) { @@ -385,6 +405,8 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len) return scsi_trace_zbc_in(p, cdb, len); case ZBC_OUT: return scsi_trace_zbc_out(p, cdb, len); + case WRITE_ATOMIC_16: + return scsi_trace_atomic_write16_out(p, cdb, len); default: return scsi_trace_misc(p, cdb, len); } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index a27f1c7f1b61..525f48c97f5e 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -939,6 +939,64 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) return scsi_alloc_sgtables(cmd); } +static void sd_config_atomic(struct scsi_disk *sdkp, struct queue_limits *lim) +{ + unsigned int logical_block_size = sdkp->device->sector_size, + physical_block_size_sectors, max_atomic, unit_min, unit_max; + + if ((!sdkp->max_atomic && !sdkp->max_atomic_with_boundary) || + sdkp->protection_type == T10_PI_TYPE2_PROTECTION) + return; + + physical_block_size_sectors = sdkp->physical_block_size / + sdkp->device->sector_size; + + unit_min = rounddown_pow_of_two(sdkp->atomic_granularity ? + sdkp->atomic_granularity : + physical_block_size_sectors); + + /* + * Only use atomic boundary when we have the odd scenario of + * sdkp->max_atomic == 0, which the spec does permit. + */ + if (sdkp->max_atomic) { + max_atomic = sdkp->max_atomic; + unit_max = rounddown_pow_of_two(sdkp->max_atomic); + sdkp->use_atomic_write_boundary = 0; + } else { + max_atomic = sdkp->max_atomic_with_boundary; + unit_max = rounddown_pow_of_two(sdkp->max_atomic_boundary); + sdkp->use_atomic_write_boundary = 1; + } + + /* + * Ensure compliance with granularity and alignment. For now, keep it + * simple and just don't support atomic writes for values mismatched + * with max_{boundary}atomic, physical block size, and + * atomic_granularity itself. + * + * We're really being distrustful by checking unit_max also... + */ + if (sdkp->atomic_granularity > 1) { + if (unit_min > 1 && unit_min % sdkp->atomic_granularity) + return; + if (unit_max > 1 && unit_max % sdkp->atomic_granularity) + return; + } + + if (sdkp->atomic_alignment > 1) { + if (unit_min > 1 && unit_min % sdkp->atomic_alignment) + return; + if (unit_max > 1 && unit_max % sdkp->atomic_alignment) + return; + } + + lim->atomic_write_hw_max = max_atomic * logical_block_size; + lim->atomic_write_hw_boundary = 0; + lim->atomic_write_hw_unit_min = unit_min * logical_block_size; + lim->atomic_write_hw_unit_max = unit_max * logical_block_size; +} + static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, bool unmap) { @@ -1237,6 +1295,26 @@ static int sd_cdl_dld(struct scsi_disk *sdkp, struct scsi_cmnd *scmd) return (hint - IOPRIO_HINT_DEV_DURATION_LIMIT_1) + 1; } +static blk_status_t sd_setup_atomic_cmnd(struct scsi_cmnd *cmd, + sector_t lba, unsigned int nr_blocks, + bool boundary, unsigned char flags) +{ + cmd->cmd_len = 16; + cmd->cmnd[0] = WRITE_ATOMIC_16; + cmd->cmnd[1] = flags; + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[12]); + if (boundary) + put_unaligned_be16(nr_blocks, &cmd->cmnd[10]); + else + put_unaligned_be16(0, &cmd->cmnd[10]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[12]); + cmd->cmnd[14] = 0; + cmd->cmnd[15] = 0; + + return BLK_STS_OK; +} + static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) { struct request *rq = scsi_cmd_to_rq(cmd); @@ -1302,6 +1380,10 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { ret = sd_setup_rw32_cmnd(cmd, write, lba, nr_blocks, protect | fua, dld); + } else if (rq->cmd_flags & REQ_ATOMIC && write) { + ret = sd_setup_atomic_cmnd(cmd, lba, nr_blocks, + sdkp->use_atomic_write_boundary, + protect | fua); } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks, protect | fua, dld); @@ -3264,7 +3346,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp, sdkp->max_ws_blocks = (u32)get_unaligned_be64(&vpd->data[36]); if (!sdkp->lbpme) - goto out; + goto config_atomic; lba_count = get_unaligned_be32(&vpd->data[20]); desc_count = get_unaligned_be32(&vpd->data[24]); @@ -3279,6 +3361,15 @@ static void sd_read_block_limits(struct scsi_disk *sdkp, get_unaligned_be32(&vpd->data[32]) & ~(1 << 31); sd_config_discard(sdkp, lim, sd_discard_mode(sdkp)); + +config_atomic: + sdkp->max_atomic = get_unaligned_be32(&vpd->data[44]); + sdkp->atomic_alignment = get_unaligned_be32(&vpd->data[48]); + sdkp->atomic_granularity = get_unaligned_be32(&vpd->data[52]); + sdkp->max_atomic_with_boundary = get_unaligned_be32(&vpd->data[56]); + sdkp->max_atomic_boundary = get_unaligned_be32(&vpd->data[60]); + + sd_config_atomic(sdkp, lim); } out: diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 7603b3c67b23..36382eca941c 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -115,6 +115,13 @@ struct scsi_disk { u32 max_unmap_blocks; u32 unmap_granularity; u32 unmap_alignment; + + u32 max_atomic; + u32 atomic_alignment; + u32 atomic_granularity; + u32 max_atomic_with_boundary; + u32 max_atomic_boundary; + u32 index; unsigned int physical_block_size; unsigned int max_medium_access_timeouts; @@ -148,6 +155,7 @@ struct scsi_disk { unsigned security : 1; unsigned ignore_medium_access_errors : 1; unsigned rscs : 1; /* reduced stream control support */ + unsigned use_atomic_write_boundary : 1; }; #define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev) diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 843106e1109f..70e1262b2e20 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -120,6 +120,7 @@ #define WRITE_SAME_16 0x93 #define ZBC_OUT 0x94 #define ZBC_IN 0x95 +#define WRITE_ATOMIC_16 0x9c #define SERVICE_ACTION_BIDIRECTIONAL 0x9d #define SERVICE_ACTION_IN_16 0x9e #define SERVICE_ACTION_OUT_16 0x9f diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h index 8e2d9b1b0e77..05f1945ed204 100644 --- a/include/trace/events/scsi.h +++ b/include/trace/events/scsi.h @@ -102,6 +102,7 @@ scsi_opcode_name(WRITE_32), \ scsi_opcode_name(WRITE_SAME_32), \ scsi_opcode_name(ATA_16), \ + scsi_opcode_name(WRITE_ATOMIC_16), \ scsi_opcode_name(ATA_12)) #define scsi_hostbyte_name(result) { result, #result } From patchwork Thu Jun 20 12:53:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705377 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 74A241B142F; Thu, 20 Jun 2024 12:56:15 +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=1718888179; cv=fail; b=YuEAjbBQmAD+FSCH1bW0WAnVn1pA5OSG9DbMwMsmQ7Y1UWY3vIjTtYCsHWFF5yGCWFjZB6s5YG/McsnL9TsSPV5ZyWsQzP3B502VrRmMGuOlcWaHgQ2jTFf1tEaA8gVu/DfSUMRCiwoOoq2eUh963y4E7X5YR2iCOqlTIpDFC9I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888179; c=relaxed/simple; bh=ze9em5INdycc48t3W3uOuCvW1UPjbfeWzsmvGwvfStw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=dLCB/O70jBvIinJAcA/1LenrukR5oDw6+djwPNorsFD30hMFzyFO5X05TggXOc/grGDD3uiSRJmkYFWOUcRYlcTbfhlDxOdpweH1ktczifMJlaCGZssbV/FepUKKf0yIKEZ9tov4WRhJiid6or+JMp7gt/EyBXiPiMkx0iIBljA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=iHapryNn; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=EIjJfsPU; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iHapryNn"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="EIjJfsPU" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5GFeQ006627; Thu, 20 Jun 2024 12:54:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=858Jelol0qWBsezANnyRhQGnX93d8f8HkvjudIBABTE=; b= iHapryNn+qZWhKyueDK3TYwc4ChGHkabp02JAxxUVR6rrCEqLK5kjuBrsZnVkYfO 2jk2E0QHx6NVOavFe/3+rJA1lbXUHP1pouXOj1KvkFJNJ31nK+mQmDDBHSHAlmWb D1NIseXBoOO7KlcGQzS2ppUiLiu64SFvEqhLUh2GYAwkZUMuegwvXnIX2H4gntaJ DKy1HtpJVNlftHH/u3o6gIj1HCj5cwFwJJpEd0G1h5DNXEDNRuuOi/VLoAsDIdiP YjFGrlXAOnzbPh6I2rcioExb1Pmy9ASQAbC5ZqgpPTJe006fqy2VQU/kQH4Z3M5S uXbNdAZlvBO3LQiOOZo3TA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9jb3yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:42 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KC7uth032824; Thu, 20 Jun 2024 12:54:41 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2040.outbound.protection.outlook.com [104.47.56.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dae6nh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W8lrBHIrXMz2XFCi8w9AUSMFo7spwWy16NZSt8e5u94gpoazRkAlLt5/TnH9j69D6bNLb83yEw0S86wbydrYHAjrYXpJQ/1Hdwe/CkRGSpL0X1+nRycdk9Tq6GffxgKrz6F01TxnnJOmZOjOn9ZcXyT3tzQnpXyHIt3uq4UfMmmsssnJSa6y1nzrR0gRFW8brP4Jgm9GfABQTwobyrpCk2ieWJRv9RyMY2nKzwvZdkObFSAjkSmBHg7Wo0JUadHvgc9rsuoG7xbzzAqg2JCQAXvXK7wQAUHo1RSa92hVRkhl8kpJ8f4FTYlCM97h1e8v4WpbylT4Z5KSGnzr2IvxJg== 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=858Jelol0qWBsezANnyRhQGnX93d8f8HkvjudIBABTE=; b=bTA4D4dw+P3NSAc+a97prs55doDnH4ITsxHsma4LWAm6pHOsod5Aa+OHc4RyjJHuG+/0wj1lv/LaMRCm5OZHcOqeWV44Fhxmoj0qmQdo2m4aA3eKA/M7U3SJECVWFJ/P+bbsAGyvSNV7uHldawiMC2qcp/aSuF4Icfjv/ItA2j+NYt8vFk5b+AqCIxPx6VviVgjcxxloZGexcFRbbZP6rvvTkofBNSUzJOublFJwravAeG3rIJ25Sy/k9+gPJ4Qk88RTMNNcvWjUCytr2VSnVQjCeJSeNSFnmfnmyp3UFMVPav55MbDtCo1IsNmnjpLBxbbsgLib0txeQlzJxr7QZQ== 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=858Jelol0qWBsezANnyRhQGnX93d8f8HkvjudIBABTE=; b=EIjJfsPUiPJC4amAfgN6GOXKmboFKAd2R6laFcj1e8qGST4A51RvrbtU7/jTWWCU81Ib/AZb9DeWKyUD29dW8r7g3V4cwJiDbRBuDmmybe0cx2Qy5wErywtuYC6ZfjOWHLfXaQveX0mBsMPLnOBTS2HSApYw21YQS2MIXDLddCY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:37 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:37 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, John Garry Subject: [Patch v9 09/10] scsi: scsi_debug: Atomic write support Date: Thu, 20 Jun 2024 12:53:58 +0000 Message-Id: <20240620125359.2684798-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR16CA0026.namprd16.prod.outlook.com (2603:10b6:208:134::39) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: d822dd19-9fab-4cf6-3bef-08dc9128248a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: d4yuUcybs+2IATS3A2Cp09g3XUnmB9fHj7QUbiuGCHjRqAUezXm4RG8DNbK2P/q0wKxqPY63EATiu+Fm0gdxhKfD24HiyO0AX+2gWEyJSpSSfj09i+FRSiw1nIZ+IcoX5RS3y6CSBUXSdBvIxAhmOT5rZqm7Pc5evceLbzWXsUbhI2LhQlUXByvVk7fT8j9+xLhYZcbb9crU7enqulrtYznogogYTHqwhwzve7IIrFsXl+NTnODdHGSUo6OItvQPSJbnam519MBecJYi3/laThAUtgMGErUed74cLE+Pw88HFPGe16XtIf1pdEVXkjPTW8/TNy6MCVwk4+AoBngilrISAUQ0Z6riAVjXJw6HnDJlc9PS+JsrVcZKrYaEqntPffYs5fBu5fo6SYRRXLswlg8AXIIuO7zB/zxn+Pna9xaQML3lw4KaeGwlZP6Q9wcYUaUJT8GFYS4M61iXhue2oLDG+K0mpusGVbcLukMkIfYxZhzdxgH1geowgJp7s1NSfrpzaoNS6PhMceLvOcz9hS3iMWmOQlXaOX+tgLBkrvNz/8sk6mAQ3WEVejQ5sTy7yf8ng8oV2lOsVSwyVUHQv/YZFDmI1zU+7McjYiWyzfLARW7cYbxJXAXU5MhRuQRBogoPSulPBBTz+xMjrP2N8A5VwDJfBRarqYiF8cKV3Hi3F1LpXqvPlXUYAYy14NOt8BbtKsYw1avzWe+QX8pGUZxBAUt26ILwAZtc5+WJ/a8BCs4gvXHgIUIJgqsUhUQQsJc5vYK9K41EYgfxVf/VN1PcGVgzjzFtz1P0b+GgfnXL+P9GdkBlXUJr+JzKOUH2EzB10A/J6NIaMA3NzcxJ75EaGT9iMDaRxvtqbQPt1lHpaxY4d1ye84jk1XVW+6kffEN9AA90zqrLtTiHqv0mNOKnRSD3VnYcjueh/tifdsqHkDBhy53AyVDokMzWsOtp7/HF9zJhLlPZH0UeEeStK1nZdGPaWJbAxrc5DkzO1W6RrSeU4jZE3Y46USgQwNH8RPqyrXCza+WZdJpQAwjQQG3kSej6CsbJypihreZf/Ok50aHJwcIC36gEA07UydKqY0YwdaynQC5uM8Q1viaLQ8P1Ie7H4o5hipwTuS8NjKamINzRj7s1Unk2VchskZcn0dqaG1zZ4qDZmjSRMJT+ibugZdf4Sz2Pgl/o5BzOg8HL6CqlV7L0CnKEsupk+tOgWGfslmn4VG6HiXjAaPMxvWiPtUUFBzjBXiZdCpHsb3wU9wyaqKqEV/hbuZoPk19jzDXEWxLSuF3gmitFpXAVKsSVSQtcC2m/Bt9wU4ei+OUfCcV62q7wl2AhjKB/bfydceChi/CPXJ5fJM8ij/mPZtEFqzE2u3yTPvOb1eXvoxk= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: khULbn95oECqU4MYKloh5FlAA7pH9ww4Je4DhDOUb0htKqa+KpFLqQnMYS0SUD9rkc7rvws2EoPsoS/rUQJAAIg8bZPI3npQNYAUUL1XBGD/bVSiql9im8cyGkEo/xZf4kgipR55by13iqLv7N4TA/EceVsQzyVbpxdle5Scjf0GWTA4TXpoxA7Oc1Y8BLXFocjoxkgBWgYJB2zjaWW47Ycfc1u4HMVjqgJyTdrwgqdWvZQ5G6uSdof1ZagzPEIW+NVtEkGkiP00VhEwqNZ/c7pdDZfRIrcYHhRFsPPumE1EvBKfTPFKQi48IKnMWmVHPrPGtpPyQAg6YU3Xic8T4kqHGx/EEIk7ve/pJ2F30hHy4AWKgVP956JWxMhOsJ8ww17Zg2yfRx07/VzNR8wERPfwQ3AOHuHtawMwiWe8DlpVGBxTkWux4rz4lSPcxyVmiK8SaXQQ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qWFQI3tiX2nzs9Ma0J7uIh2t7HudTNnAJoccdat7lp7pOh/pedhn1XVKwWqyE7KKxjYrYrQV39pPxaaC+NLHA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tzvE9d+CP0jzIMwvtWjMct7cyWpZNZtsrvSohcFFj5vFd0fZA395kGkYmxYviDQMXE5JYfysJZBqmjOCCT3+Hpz/fqeoyxJKGAjlr01c14S/JKwpbJAVKGmKX8SZjS8Tajm2hSRSbo9jWcF/KGuGRsZEIqmFsDtIHYSaDISe47xxoK5nNzmdo2TWynCvXriyd+Av5R2wa5+t5jH78g/lkQbatqdNt9qocuYF4xaa53GTtGGKMI+YyTPuyGqpiAmJIQos4RQ0imWgmEAqk+4Ndv32uU9fSb3ws5Cw+Ak44Up8f6/e2EBeO7jN0RnHDjvex9I9s65kGdaEM9B/VuD/yRRBu1I8Id0iPYGRpjDYujqiJ77Uijy0+ik3g13+4glxaPNWxeehPcq/KJaZ550OFW3wQUr8a4alkGBTZja0yJ4B6PAx1WMT87nMXqmKzv+msTvPmRQrtyHISf4FKccwYDWM3oMUkSMiSQDWbM3rwNZ1QmTc3H59iSOeLtMT0fMpLpHtmEhPCb8fz8quaAZ6hzG5gUnLkQ0crGwM8H1w2N/z1VZdx52VDCyb/L/2H7lhaJeI4/ACpf+R2q1zIX3oihYssF/KwVcZd9IXGqEz1Z4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d822dd19-9fab-4cf6-3bef-08dc9128248a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:37.8845 (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: s9iU9zXVOFBepC9z0YXo2d54STqPfT/4ksJvtc/t/MbyrmC4ppqg1GSYho+4ZtdFqwWcbbQMmj1EVUVzTI3lHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-GUID: sgo-roy4YH4y3zn3WCFSdnDr5oQBaSvu X-Proofpoint-ORIG-GUID: sgo-roy4YH4y3zn3WCFSdnDr5oQBaSvu Add initial support for atomic writes. As is standard method, feed device properties via modules param, those being: - atomic_max_size_blks - atomic_alignment_blks - atomic_granularity_blks - atomic_max_size_with_boundary_blks - atomic_max_boundary_blks These just match sbc4r22 section 6.6.4 - Block limits VPD page. We just support ATOMIC WRITE (16). The major change in the driver is how we lock the device for RW accesses. Currently the driver uses a per-device lock for accessing device metadata and "media" data (calls to do_device_access()) atomically for the duration of the whole read/write command. This should not suit verifying atomic writes. Reason being that currently all reads/writes are atomic, so using atomic writes does not prove anything. Change device access model to basis that regular writes only atomic on a per-sector basis, while reads and atomic writes are fully atomic. As mentioned, since accessing metadata and device media is atomic, continue to have regular writes involving metadata - like discard or PI - as atomic. We can improve this later. Currently we only support model where overlapping going reads or writes wait for current access to complete before commencing an atomic write. This is described in 4.29.3.2 section of the SBC. However, we simplify, things and wait for all accesses to complete (when issuing an atomic write). Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi_debug.c | 588 +++++++++++++++++++++++++++++--------- 1 file changed, 454 insertions(+), 134 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 7f340a59fdc5..fcc9640fa18a 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -69,6 +69,8 @@ static const char *sdebug_version_date = "20210520"; /* Additional Sense Code (ASC) */ #define NO_ADDITIONAL_SENSE 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASC 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASCQ 0x23 #define LOGICAL_UNIT_NOT_READY 0x4 #define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8 #define UNRECOVERED_READ_ERR 0x11 @@ -103,6 +105,7 @@ static const char *sdebug_version_date = "20210520"; #define READ_BOUNDARY_ASCQ 0x7 #define ATTEMPT_ACCESS_GAP 0x9 #define INSUFF_ZONE_ASCQ 0xe +/* see drivers/scsi/sense_codes.h */ /* Additional Sense Code Qualifier (ASCQ) */ #define ACK_NAK_TO 0x3 @@ -152,6 +155,12 @@ static const char *sdebug_version_date = "20210520"; #define DEF_VIRTUAL_GB 0 #define DEF_VPD_USE_HOSTNO 1 #define DEF_WRITESAME_LENGTH 0xFFFF +#define DEF_ATOMIC_WR 0 +#define DEF_ATOMIC_WR_MAX_LENGTH 8192 +#define DEF_ATOMIC_WR_ALIGN 2 +#define DEF_ATOMIC_WR_GRAN 2 +#define DEF_ATOMIC_WR_MAX_LENGTH_BNDRY (DEF_ATOMIC_WR_MAX_LENGTH) +#define DEF_ATOMIC_WR_MAX_BNDRY 128 #define DEF_STRICT 0 #define DEF_STATISTICS false #define DEF_SUBMIT_QUEUES 1 @@ -374,7 +383,9 @@ struct sdebug_host_info { /* There is an xarray of pointers to this struct's objects, one per host */ struct sdeb_store_info { - rwlock_t macc_lck; /* for atomic media access on this store */ + rwlock_t macc_data_lck; /* for media data access on this store */ + rwlock_t macc_meta_lck; /* for atomic media meta access on this store */ + rwlock_t macc_sector_lck; /* per-sector media data access on this store */ u8 *storep; /* user data storage (ram) */ struct t10_pi_tuple *dif_storep; /* protection info */ void *map_storep; /* provisioning map */ @@ -398,12 +409,20 @@ struct sdebug_defer { enum sdeb_defer_type defer_t; }; +struct sdebug_device_access_info { + bool atomic_write; + u64 lba; + u32 num; + struct scsi_cmnd *self; +}; + struct sdebug_queued_cmd { /* corresponding bit set in in_use_bm[] in owning struct sdebug_queue * instance indicates this slot is in use. */ struct sdebug_defer sd_dp; struct scsi_cmnd *scmd; + struct sdebug_device_access_info *i; }; struct sdebug_scsi_cmd { @@ -463,7 +482,8 @@ enum sdeb_opcode_index { SDEB_I_PRE_FETCH = 29, /* 10, 16 */ SDEB_I_ZONE_OUT = 30, /* 0x94+SA; includes no data xfer */ SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */ - SDEB_I_LAST_ELEM_P1 = 32, /* keep this last (previous + 1) */ + SDEB_I_ATOMIC_WRITE_16 = 32, + SDEB_I_LAST_ELEM_P1 = 33, /* keep this last (previous + 1) */ }; @@ -497,7 +517,8 @@ static const unsigned char opcode_ind_arr[256] = { 0, 0, 0, SDEB_I_VERIFY, SDEB_I_PRE_FETCH, SDEB_I_SYNC_CACHE, 0, SDEB_I_WRITE_SAME, SDEB_I_ZONE_OUT, SDEB_I_ZONE_IN, 0, 0, - 0, 0, 0, 0, 0, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, + 0, 0, 0, 0, + SDEB_I_ATOMIC_WRITE_16, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, /* 0xa0; 0xa0->0xbf: 12 byte cdbs */ SDEB_I_REPORT_LUNS, SDEB_I_ATA_PT, 0, SDEB_I_MAINT_IN, SDEB_I_MAINT_OUT, 0, 0, 0, @@ -547,6 +568,7 @@ static int resp_write_buffer(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_sync_cache(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_pre_fetch(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_report_zones(struct scsi_cmnd *, struct sdebug_dev_info *); +static int resp_atomic_write(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_open_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_close_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_finish_zone(struct scsi_cmnd *, struct sdebug_dev_info *); @@ -788,6 +810,11 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEM_P1 + 1] = { resp_report_zones, zone_in_iarr, /* ZONE_IN(16), REPORT ZONES) */ {16, 0x0 /* SA */, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xc7} }, +/* 31 */ + {0, 0x0, 0x0, F_D_OUT | FF_MEDIA_IO, + resp_atomic_write, NULL, /* ATOMIC WRITE 16 */ + {16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} }, /* sentinel */ {0xff, 0, 0, 0, NULL, NULL, /* terminating element */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, @@ -835,6 +862,13 @@ static unsigned int sdebug_unmap_granularity = DEF_UNMAP_GRANULARITY; static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC; static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH; +static unsigned int sdebug_atomic_wr = DEF_ATOMIC_WR; +static unsigned int sdebug_atomic_wr_max_length = DEF_ATOMIC_WR_MAX_LENGTH; +static unsigned int sdebug_atomic_wr_align = DEF_ATOMIC_WR_ALIGN; +static unsigned int sdebug_atomic_wr_gran = DEF_ATOMIC_WR_GRAN; +static unsigned int sdebug_atomic_wr_max_length_bndry = + DEF_ATOMIC_WR_MAX_LENGTH_BNDRY; +static unsigned int sdebug_atomic_wr_max_bndry = DEF_ATOMIC_WR_MAX_BNDRY; static int sdebug_uuid_ctl = DEF_UUID_CTL; static bool sdebug_random = DEF_RANDOM; static bool sdebug_per_host_store = DEF_PER_HOST_STORE; @@ -1188,6 +1222,11 @@ static inline bool scsi_debug_lbp(void) (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10); } +static inline bool scsi_debug_atomic_write(void) +{ + return sdebug_fake_rw == 0 && sdebug_atomic_wr; +} + static void *lba2fake_store(struct sdeb_store_info *sip, unsigned long long lba) { @@ -1815,6 +1854,14 @@ static int inquiry_vpd_b0(unsigned char *arr) /* Maximum WRITE SAME Length */ put_unaligned_be64(sdebug_write_same_length, &arr[32]); + if (sdebug_atomic_wr) { + put_unaligned_be32(sdebug_atomic_wr_max_length, &arr[40]); + put_unaligned_be32(sdebug_atomic_wr_align, &arr[44]); + put_unaligned_be32(sdebug_atomic_wr_gran, &arr[48]); + put_unaligned_be32(sdebug_atomic_wr_max_length_bndry, &arr[52]); + put_unaligned_be32(sdebug_atomic_wr_max_bndry, &arr[56]); + } + return 0x3c; /* Mandatory page length for Logical Block Provisioning */ } @@ -3377,16 +3424,238 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip, return xa_load(per_store_ap, devip->sdbg_host->si_idx); } +static inline void +sdeb_read_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + read_lock(lock); +} + +static inline void +sdeb_read_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + read_unlock(lock); +} + +static inline void +sdeb_write_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + write_lock(lock); +} + +static inline void +sdeb_write_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + write_unlock(lock); +} + +static inline void +sdeb_data_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_sector_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_sector_lck); +} + +/* + * Atomic locking: + * We simplify the atomic model to allow only 1x atomic write and many non- + * atomic reads or writes for all LBAs. + + * A RW lock has a similar bahaviour: + * Only 1x writer and many readers. + + * So use a RW lock for per-device read and write locking: + * An atomic access grabs the lock as a writer and non-atomic grabs the lock + * as a reader. + */ + +static inline void +sdeb_data_lock(struct sdeb_store_info *sip, bool atomic) +{ + if (atomic) + sdeb_data_write_lock(sip); + else + sdeb_data_read_lock(sip); +} + +static inline void +sdeb_data_unlock(struct sdeb_store_info *sip, bool atomic) +{ + if (atomic) + sdeb_data_write_unlock(sip); + else + sdeb_data_read_unlock(sip); +} + +/* Allow many reads but only 1x write per sector */ +static inline void +sdeb_data_sector_lock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_lock(sip); + else + sdeb_data_sector_read_lock(sip); +} + +static inline void +sdeb_data_sector_unlock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_unlock(sip); + else + sdeb_data_sector_read_unlock(sip); +} + +static inline void +sdeb_meta_read_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + read_lock(&sip->macc_meta_lck); + else + read_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_read_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + read_unlock(&sip->macc_meta_lck); + else + read_unlock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + write_lock(&sip->macc_meta_lck); + else + write_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + write_unlock(&sip->macc_meta_lck); + else + write_unlock(&sdeb_fake_rw_lck); + } +} + /* Returns number of bytes copied or -1 if error. */ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, - u32 sg_skip, u64 lba, u32 num, bool do_write, - u8 group_number) + u32 sg_skip, u64 lba, u32 num, u8 group_number, + bool do_write, bool atomic) { int ret; - u64 block, rest = 0; + u64 block; enum dma_data_direction dir; struct scsi_data_buffer *sdb = &scp->sdb; u8 *fsp; + int i; + + /* + * Even though reads are inherently atomic (in this driver), we expect + * the atomic flag only for writes. + */ + if (!do_write && atomic) + return -1; if (do_write) { dir = DMA_TO_DEVICE; @@ -3406,21 +3675,26 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, fsp = sip->storep; block = do_div(lba, sdebug_store_sectors); - if (block + num > sdebug_store_sectors) - rest = block + num - sdebug_store_sectors; - ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, + /* Only allow 1x atomic write or multiple non-atomic writes at any given time */ + sdeb_data_lock(sip, atomic); + for (i = 0; i < num; i++) { + /* We shouldn't need to lock for atomic writes, but do it anyway */ + sdeb_data_sector_lock(sip, do_write); + ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, fsp + (block * sdebug_sector_size), - (num - rest) * sdebug_sector_size, sg_skip, do_write); - if (ret != (num - rest) * sdebug_sector_size) - return ret; - - if (rest) { - ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, - fsp, rest * sdebug_sector_size, - sg_skip + ((num - rest) * sdebug_sector_size), - do_write); + sdebug_sector_size, sg_skip, do_write); + sdeb_data_sector_unlock(sip, do_write); + if (ret != sdebug_sector_size) { + ret += (i * sdebug_sector_size); + break; + } + sg_skip += sdebug_sector_size; + if (++block >= sdebug_store_sectors) + block = 0; } + ret = num * sdebug_sector_size; + sdeb_data_unlock(sip, atomic); return ret; } @@ -3596,70 +3870,6 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec, return ret; } -static inline void -sdeb_read_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - read_lock(&sip->macc_lck); - else - read_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_read_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - read_unlock(&sip->macc_lck); - else - read_unlock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - write_lock(&sip->macc_lck); - else - write_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - write_unlock(&sip->macc_lck); - else - write_unlock(&sdeb_fake_rw_lck); - } -} - static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) { bool check_prot; @@ -3669,6 +3879,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case READ_16: @@ -3727,6 +3938,10 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) atomic_set(&sdeb_inject_pending, 0); } + /* + * When checking device access params, for reads we only check data + * versus what is set at init time, so no need to lock. + */ ret = check_device_access_params(scp, lba, num, false); if (ret) return ret; @@ -3746,29 +3961,33 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_read_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp))) { + sdeb_meta_read_lock(sip); + meta_data_locked = true; + } /* DIX + T10 DIF */ if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) { switch (prot_verify_read(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } break; case 3: /* Reference tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } @@ -3776,8 +3995,9 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, false, 0); - sdeb_read_unlock(sip); + ret = do_device_access(sip, scp, 0, lba, num, 0, false, false); + if (meta_data_locked) + sdeb_meta_read_unlock(sip); if (unlikely(ret == -1)) return DID_ERROR << 16; @@ -3967,6 +4187,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case WRITE_16: @@ -4025,10 +4246,17 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) "to DIF device\n"); } - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp)) || + scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } + ret = check_device_access_params(scp, lba, num, true); if (ret) { - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); return ret; } @@ -4037,22 +4265,22 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) switch (prot_verify_write(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } break; case 3: /* Reference tag error */ if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } @@ -4060,13 +4288,16 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, true, group); + ret = do_device_access(sip, scp, 0, lba, num, group, true, false); if (unlikely(scsi_debug_lbp())) map_region(sip, lba, num); + /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + if (unlikely(-1 == ret)) return DID_ERROR << 16; else if (unlikely(sdebug_verbose && @@ -4176,7 +4407,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, goto err_out; } - sdeb_write_lock(sip); + /* Just keep it simple and always lock for now */ + sdeb_meta_write_lock(sip); sg_off = lbdof_blen; /* Spec says Buffer xfer Length field in number of LBs in dout */ cum_lb = 0; @@ -4219,7 +4451,11 @@ static int resp_write_scat(struct scsi_cmnd *scp, } } - ret = do_device_access(sip, scp, sg_off, lba, num, true, group); + /* + * Write ranges atomically to keep as close to pre-atomic + * writes behaviour as possible. + */ + ret = do_device_access(sip, scp, sg_off, lba, num, group, true, true); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); @@ -4258,7 +4494,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, } ret = 0; err_out_unlock: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); err_out: kfree(lrdp); return ret; @@ -4277,14 +4513,16 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, scp->device->hostdata, true); u8 *fs1p; u8 *fsp; + bool meta_data_locked = false; - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } ret = check_device_access_params(scp, lba, num, true); - if (ret) { - sdeb_write_unlock(sip); - return ret; - } + if (ret) + goto out; if (unmap && scsi_debug_lbp()) { unmap_region(sip, lba, num); @@ -4295,6 +4533,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* if ndob then zero 1 logical block, else fetch 1 logical block */ fsp = sip->storep; fs1p = fsp + (block * lb_size); + sdeb_data_write_lock(sip); if (ndob) { memset(fs1p, 0, lb_size); ret = 0; @@ -4302,8 +4541,8 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ret = fetch_to_dev_buffer(scp, fs1p, lb_size); if (-1 == ret) { - sdeb_write_unlock(sip); - return DID_ERROR << 16; + ret = DID_ERROR << 16; + goto out; } else if (sdebug_verbose && !ndob && (ret < lb_size)) sdev_printk(KERN_INFO, scp->device, "%s: %s: lb size=%u, IO sent=%d bytes\n", @@ -4320,10 +4559,12 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); + sdeb_data_write_unlock(sip); + ret = 0; out: - sdeb_write_unlock(sip); - - return 0; + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + return ret; } static int resp_write_same_10(struct scsi_cmnd *scp, @@ -4466,25 +4707,30 @@ static int resp_comp_write(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); - ret = do_dout_fetch(scp, dnum, arr); if (ret == -1) { retval = DID_ERROR << 16; - goto cleanup; + goto cleanup_free; } else if (sdebug_verbose && (ret < (dnum * lb_size))) sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " "indicated=%u, IO sent=%d bytes\n", my_name, dnum * lb_size, ret); + + sdeb_data_write_lock(sip); + sdeb_meta_write_lock(sip); if (!comp_write_worker(sip, lba, num, arr, false)) { mk_sense_buffer(scp, MISCOMPARE, MISCOMPARE_VERIFY_ASC, 0); retval = check_condition_result; - goto cleanup; + goto cleanup_unlock; } + + /* Cover sip->map_storep (which map_region()) sets with data lock */ if (scsi_debug_lbp()) map_region(sip, lba, num); -cleanup: - sdeb_write_unlock(sip); +cleanup_unlock: + sdeb_meta_write_unlock(sip); + sdeb_data_write_unlock(sip); +cleanup_free: kfree(arr); return retval; } @@ -4528,7 +4774,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) desc = (void *)&buf[8]; - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); for (i = 0 ; i < descriptors ; i++) { unsigned long long lba = get_unaligned_be64(&desc[i].lba); @@ -4544,7 +4790,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ret = 0; out: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); kfree(buf); return ret; @@ -4702,12 +4948,13 @@ static int resp_pre_fetch(struct scsi_cmnd *scp, rest = block + nblks - sdebug_store_sectors; /* Try to bring the PRE-FETCH range into CPU's cache */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); prefetch_range(fsp + (sdebug_sector_size * block), (nblks - rest) * sdebug_sector_size); if (rest) prefetch_range(fsp, rest * sdebug_sector_size); - sdeb_read_unlock(sip); + + sdeb_data_read_unlock(sip); fini: if (cmd[1] & 0x2) res = SDEG_RES_IMMED_MASK; @@ -4866,7 +5113,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } /* Not changing store, so only need read access */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); ret = do_dout_fetch(scp, a_num, arr); if (ret == -1) { @@ -4888,7 +5135,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) goto cleanup; } cleanup: - sdeb_read_unlock(sip); + sdeb_data_read_unlock(sip); kfree(arr); return ret; } @@ -4934,7 +5181,7 @@ static int resp_report_zones(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_read_lock(sip); + sdeb_meta_read_lock(sip); desc = arr + 64; for (lba = zs_lba; lba < sdebug_capacity; @@ -5032,11 +5279,70 @@ static int resp_report_zones(struct scsi_cmnd *scp, ret = fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, rep_len)); fini: - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); kfree(arr); return ret; } +static int resp_atomic_write(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip) +{ + struct sdeb_store_info *sip; + u8 *cmd = scp->cmnd; + u16 boundary, len; + u64 lba, lba_tmp; + int ret; + + if (!scsi_debug_atomic_write()) { + mk_sense_invalid_opcode(scp); + return check_condition_result; + } + + sip = devip2sip(devip, true); + + lba = get_unaligned_be64(cmd + 2); + boundary = get_unaligned_be16(cmd + 10); + len = get_unaligned_be16(cmd + 12); + + lba_tmp = lba; + if (sdebug_atomic_wr_align && + do_div(lba_tmp, sdebug_atomic_wr_align)) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (sdebug_atomic_wr_gran && len % sdebug_atomic_wr_gran) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (boundary > 0) { + if (boundary > sdebug_atomic_wr_max_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + + if (len > sdebug_atomic_wr_max_length_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } else { + if (len > sdebug_atomic_wr_max_length) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } + + ret = do_device_access(sip, scp, 0, lba, len, 0, true, true); + if (unlikely(ret == -1)) + return DID_ERROR << 16; + if (unlikely(ret != len * sdebug_sector_size)) + return DID_ERROR << 16; + return 0; +} + /* Logic transplanted from tcmu-runner, file_zbc.c */ static void zbc_open_all(struct sdebug_dev_info *devip) { @@ -5063,8 +5369,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) mk_sense_invalid_opcode(scp); return check_condition_result; } - - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { /* Check if all closed zones can be open */ @@ -5113,7 +5418,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_open_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5140,7 +5445,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_close_all(devip); @@ -5169,7 +5474,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, zbc_close_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5212,7 +5517,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_finish_all(devip); @@ -5241,7 +5546,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, zbc_finish_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5292,7 +5597,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_rwp_all(devip); @@ -5320,7 +5625,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_rwp_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -6284,6 +6589,7 @@ module_param_named(lbprz, sdebug_lbprz, int, S_IRUGO); module_param_named(lbpu, sdebug_lbpu, int, S_IRUGO); module_param_named(lbpws, sdebug_lbpws, int, S_IRUGO); module_param_named(lbpws10, sdebug_lbpws10, int, S_IRUGO); +module_param_named(atomic_wr, sdebug_atomic_wr, int, S_IRUGO); module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO); module_param_named(lun_format, sdebug_lun_am_i, int, S_IRUGO | S_IWUSR); module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR); @@ -6318,6 +6624,11 @@ module_param_named(unmap_alignment, sdebug_unmap_alignment, int, S_IRUGO); module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO); module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO); module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO); +module_param_named(atomic_wr_max_length, sdebug_atomic_wr_max_length, int, S_IRUGO); +module_param_named(atomic_wr_align, sdebug_atomic_wr_align, int, S_IRUGO); +module_param_named(atomic_wr_gran, sdebug_atomic_wr_gran, int, S_IRUGO); +module_param_named(atomic_wr_max_length_bndry, sdebug_atomic_wr_max_length_bndry, int, S_IRUGO); +module_param_named(atomic_wr_max_bndry, sdebug_atomic_wr_max_bndry, int, S_IRUGO); module_param_named(uuid_ctl, sdebug_uuid_ctl, int, S_IRUGO); module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR); module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int, @@ -6361,6 +6672,7 @@ MODULE_PARM_DESC(lbprz, MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)"); MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)"); MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)"); +MODULE_PARM_DESC(atomic_write, "enable ATOMIC WRITE support, support WRITE ATOMIC(16) (def=0)"); MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)"); MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method"); MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); @@ -6392,6 +6704,11 @@ MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)" MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)"); MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)"); MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)"); +MODULE_PARM_DESC(atomic_wr_max_length, "max # of blocks can be atomically written in one cmd (def=8192)"); +MODULE_PARM_DESC(atomic_wr_align, "minimum alignment of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_gran, "minimum granularity of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_max_length_bndry, "max # of blocks can be atomically written in one cmd with boundary set (def=8192)"); +MODULE_PARM_DESC(atomic_wr_max_bndry, "max # boundaries per atomic write (def=128)"); MODULE_PARM_DESC(uuid_ctl, "1->use uuid for lu name, 0->don't, 2->all use same (def=0)"); MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)"); @@ -7563,6 +7880,7 @@ static int __init scsi_debug_init(void) return -EINVAL; } } + xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); if (want_store) { idx = sdebug_add_store(); @@ -7770,7 +8088,9 @@ static int sdebug_add_store(void) map_region(sip, 0, 2); } - rwlock_init(&sip->macc_lck); + rwlock_init(&sip->macc_data_lck); + rwlock_init(&sip->macc_meta_lck); + rwlock_init(&sip->macc_sector_lck); return (int)n_idx; err: sdebug_erase_store((int)n_idx, sip); From patchwork Thu Jun 20 12:53:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13705378 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 75AB41B14FD; Thu, 20 Jun 2024 12:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888181; cv=fail; b=kBhJT+qoGEM/Q6HabJFTt2XgY8wgnVBspjBM2fQve8kS5x12DGa+kBm6ECujzFW39NoGcDuNG0hZbNyk+srORLhhx7aWzbYBSRKhvGgFVnj1TbgM0zUsiSXmjwW9sxRALgLIUkAkIEdKVI5ooYVj78uu1t3J0nU9NTXNLZR1HGw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888181; c=relaxed/simple; bh=lqISxX5YEW/WeNeJDQSw1eC99xDJXb80NYGmqhZ9p5c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=iQ2dorIELyZYAbQ0N/i4vF8kW0AdSjyC2R1eu6aEGoWdIA0Tc0VS/x2E9Az9ym2jtSiHchoSrKZNqQ3NCEYCGVVLfYdnXcAQ6kQW8L7dW69AE5vCpseBGDeVfyGalz+18RMoCyhwapYQFmWm5nz7AAV2K5jV9tSiPNnn7PD11Z4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=e1AbHarY; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=zEgXscnz; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="e1AbHarY"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="zEgXscnz" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45K5Fik1002321; Thu, 20 Jun 2024 12:54:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding:mime-version; s= corp-2023-11-20; bh=CeXcO95RprRpKSW+3sToKcTkGBFVJhtusSrxlskOoZE=; b= e1AbHarY76DbR5zemdvNUoFUU5D6HTCfPdO+bmvWmMZUZIOEhtrcXlt0IFC0Qb6X wfthagKmN61ibUbTk6csgbz4LhHEfqfyPGazysoK+MVJgzL6uMsrYN4NrlezUkmv sY0z84Jzn0Tn9dIXOeb6OZ6s1HPrQ6qG/K7eoUTl74wqSVplxRWOx59pfPbMlS3W KO7OcdraihYD92EVsFIirtfGu//DwzCY2w4mHeoCPYHyM0rrmlBo2LkjLFip6oPR zh6iD6W1pumGzGxe9BZ/Y7wbEAn6YAHMZ+Q7BUqABSdXInsGCD3n0WvSgoqwq9r1 BxoZLHCxHRfgG24YDoq3tw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yuj9r34ha-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:42 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45KC7uti032824; Thu, 20 Jun 2024 12:54:42 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2040.outbound.protection.outlook.com [104.47.56.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ys1dae6nh-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2024 12:54:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kku7jG3OpQ5oBSCk8mS2PI4gdLOJfdEayGL5F4ti+3BWGfZEETl7K4k/ay2jWnBinC5iOzafc90JMW3gBP5Z+CfgAqJf7UiJoI+sOt8TVhw5lk52ZnktVoZ1yoV1SXO2Ir2nOWRMOujw5POtbNEWwyEKJvZF2wTgJsVesNay2YmoyifKZ21CzUk1A84axwVN1S0xeKC1LrcPv5cr1cOgVbi3eYUYmBF3FUpSXisAIK1g4lhQeLZcaLVew80tgTLsBSVZyT59fmRXAcyrpYjDR0mDkH9nDu0ulOjtNzMwtHlcpcTpwiB3/Ol1rVr6jHiMiTEZ8umt6BF45/8vi1tsSQ== 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=CeXcO95RprRpKSW+3sToKcTkGBFVJhtusSrxlskOoZE=; b=B37tuutpy+kBlWIOEsXEwYxEzXDh9Ck5U0UOJz6Ts75LRQnTxM3vuZ0oPnrA8g/7qcVPAlYgUYycQHUb6PCN8IHVk3QfaqfDtsxaBJMwlzVpUKspPSDXpB6dMIM6dz4yO743Tmzi0N9PliSg7ChsMTeg10Z5mXQKpDO8UyKHCl3qMbvELZ35FL+kmf/Aqt/wQVIzqNtKLf03wqyf7RJYxSvhYzi0laVkzVaUk4uhZR4lCG07CDHC1rGF/j7lZJ3QCTKfktKlYstxaJ7iQpcs1/bUsYaZepUTLx2Q9WXY4yD26vRhuZYD5vU9TbxOjPhzmh3fhfyqOvHi4gWbD7AENQ== 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=CeXcO95RprRpKSW+3sToKcTkGBFVJhtusSrxlskOoZE=; b=zEgXscnz0krTwBbSznqUSL14IjNs1VKsIxMGdqcuJTC1DnQLQwsVKzr2pBLWyjPQg3G8U7wsTo/WEoLUgo/CdZtz6PfZxXDRRJ9cvftrzbXM90/Pp4K00g18ul06KiSzkEaLgfZKuv+k5bv2ARtRzJgtrwopjKyOiUX97blb5AE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB7695.namprd10.prod.outlook.com (2603:10b6:510:2e5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31; Thu, 20 Jun 2024 12:54:39 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7698.020; Thu, 20 Jun 2024 12:54:39 +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, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: djwong@kernel.org, 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, agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, hare@suse.de, Alan Adamson , John Garry Subject: [Patch v9 10/10] nvme: Atomic write support Date: Thu, 20 Jun 2024 12:53:59 +0000 Message-Id: <20240620125359.2684798-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240620125359.2684798-1-john.g.garry@oracle.com> References: <20240620125359.2684798-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0303.namprd13.prod.outlook.com (2603:10b6:208:2c1::8) 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_|PH7PR10MB7695:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cba38a3-da64-4c9b-ff1b-08dc91282529 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|921017; X-Microsoft-Antispam-Message-Info: =?utf-8?q?YrZhW+2Q5OZBU4/1akC3F41E5r1pg4V?= =?utf-8?q?DtRP4PQmj9V0Z2R974hZD/5iCV4aYkEPtiFeCKHClS4/YYXmVQpFBtI5azBWoM3e8?= =?utf-8?q?VeXqaMHwCmMwzfCoeLpnTbi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7kif8KQGZADFswylNmL9VShvoRCPK?= =?utf-8?q?dd94HbCUiQHJYixZggWM427pQ1EOPzTSdmosPYpM27C9/BqG9Srrk5Er3VDA7Td+N?= =?utf-8?q?GozZ6t0pXElNmRZQe7A70UKfZEmWrzc5xFRIzHxg5A8pXERwHK4SY49IkAZ7Mh1UB?= =?utf-8?q?0oKMhniBcTyiuqxTKqB+fBvt4vtAs/ohKvIgkjXKzitvIUFkhhK5JLNVusOw/m20p?= =?utf-8?q?niVm+VJ1YM6hz9896b48cSVgth8ldIEWtjLXt24GdbA75TAVEa0VS+xfe8/Qj75x4?= =?utf-8?q?PXsNlSOqozCg9kP0VlGqWVIXB9W3NnPko02K3IKQa0sqBW1TTBWEJxX0=3D?= 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:(13230037)(376011)(7416011)(1800799021)(366013)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xCwqRs30ucm4tUcKh6zJcQfPQHnZ?= =?utf-8?q?2R4kyNnYlpgTu56IDXudBPY1rXQtS1EW/QEur4v+gnV9erUy+kFe0cfD8kNXXi/By?= =?utf-8?q?68unK4tCG2hXh/pMXwaNFAXShsX5b4okeBI1u6h3tomP1mOgcuSChENGFseB5ztfl?= =?utf-8?q?84bIZOUSHMOvqOn4jlrttk5TqhUSQbV34YsRcYB7czTCaKOhJ5d5H65+4c9NU1rau?= =?utf-8?q?41zAYr4Delb7PFZOLq+9XDq53OfJkKJXEcaGKG5hukySxE/ldl2qbrYVNxJR6Yg4+?= =?utf-8?q?FAmkOQlLgHkMlDUVUZWu9xVBb7BcEICRjGQ4bHwQ0f4epGRlIUb+Ns1okW+Ser32b?= =?utf-8?q?MTPYG8qtN+XL6F3l0UN5FAZB6Nz0/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+JzxOhJQV5AtESYlpUITbk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6cba38a3-da64-4c9b-ff1b-08dc91282529 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:54:39.0004 (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: ThZraPXp9QLH9lUzfTz2C+sMxdaVhZcZ/Q9+wFsdXCVpDw/n7bkfa1SE0MVC4Aouo5iBwtVkMedvNpRB5fxA7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB7695 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-20_07,2024-06-20_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406200092 X-Proofpoint-GUID: mNS_5icj699YxJY16q4thhmq4cZy4-aS X-Proofpoint-ORIG-GUID: mNS_5icj699YxJY16q4thhmq4cZy4-aS 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 Reviewed-by: Martin K. Petersen jpg: total rewrite Signed-off-by: John Garry Reviewed-by: Keith Busch Reviewed-by: Hannes Reinecke Reviewed-by: Kanchan Joshi --- drivers/nvme/host/core.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index bf410d10b120..89ebfa89613e 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -927,6 +927,36 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns, return BLK_STS_OK; } +/* + * NVMe does not support a dedicated command to issue an atomic write. A write + * which does adhere to the device atomic limits will silently be executed + * non-atomically. The request issuer should ensure that the write is within + * the queue atomic writes limits, but just validate this in case it is not. + */ +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) @@ -942,6 +972,9 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, if (req->cmd_flags & REQ_RAHEAD) dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH; + if (req->cmd_flags & REQ_ATOMIC && !nvme_valid_atomic_write(req)) + return BLK_STS_INVAL; + cmnd->rw.opcode = op; cmnd->rw.flags = 0; cmnd->rw.nsid = cpu_to_le32(ns->head->ns_id); @@ -1920,6 +1953,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; @@ -1966,6 +2016,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) {