From patchwork Mon Jun 10 10:43:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691858 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 2BF0680C16; Mon, 10 Jun 2024 10:44:45 +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=1718016290; cv=fail; b=W+TnNM/jSuc+sounOFEtoeDvMM14wuWLZeUv5KCPgAiyWk9lVj+S6X9Ntdgf8h067jpNwbJ876TUm8jmorep5eTDmZ2E7gkshOnvcaBTfWzs3N3odz95ht24zmLGAqApjqbW5NqHGsaB4J/4wJL6zMD3fAqUWK2vXrFvFWv5j2I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016290; c=relaxed/simple; bh=sYzv2/7CLjhTxrPCvjggytRPAhhChubeQp/fn06W5vk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=BQvwagxnPdDBXQEd+MJ/da9+Ha7W4UR+oLeZHADnSMjCIpOjhNZBgX52b7O+n1jTjDQRv4PxvmNM7vtOfxsdgGw/l6A1PrfMEAubHJLYo2/i0ztaW0epEKWla89c+VEYrkd28AEDshera4aBk1nvd877MvJKrbh9YX5Tly5ntpc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=UV+BZ6b5; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=bgx3YNnp; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="UV+BZ6b5"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="bgx3YNnp" 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 45A4DB7f027821; Mon, 10 Jun 2024 10:43:54 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=shf0PkL9/9+tX8AihW0X6p7w8J03sVGQV65DSX6gEZI=; b= UV+BZ6b561LrbwDz7KwslczJFYoGkd6cCY4Be7mzhLatmOhoic7Sxj8aD5A0GJcS GKO0sfAJR78l6C1Lrl0GVUcTtOCdWNNEeViM1tlpotsXZT2WlqKjT54yf6JdVYy7 JfedoZ97ALf0s3aZuuKFwZOvtQabm2weUsLOjKGo/3F7Z/e5D1EV+zK3YTGDgNa4 Q9iaJtr9JXM6/ljlcsdgwMHD3Ux+CKAMeVxY/bHztzemk+W3yABeBUl+u/sfkacc bQlEfZ1ZhuH1oRh0WuQBsIaT+jhMFVNpFMRvV2SSJwdmsuZ8sSxhsq7pWmbgmX50 Sfm4GcW2ErMZnj0NMGfFQQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1gaag3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:54 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45AA37Ov020460; Mon, 10 Jun 2024 10:43:53 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncasued1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lfi7tUASTmU4EjSjKE77jdCIVbHYVpZcZfnvrY+qu8m4YObdSJyq9a2tm9RlZLU6O3rs+QYodpms1AfTy+OjrqX/KP0lVBGC0etA4vkcNBc+ZCh9B4NFwCyDXxsYEhkiubzraeCNNkhICBOYZRtq4B3piUHc5lnNVXkqqCAQ9RRn11VSLp6e0tF6ebLvbUomzI3Ag1R25yQwKECsyw1Tb/kysZf0I5CI8rsZktFmVNaUaNdymtUqA2qJRSnqIoWsLEnkfQj+noz0giAPNnJ7qDupg2j9D5Z/cHTa2vj6VyU4gSFV/tZ+0kKPbFJMJMrm7fUm6oLU/5B/TH8IiuA1jQ== 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=shf0PkL9/9+tX8AihW0X6p7w8J03sVGQV65DSX6gEZI=; b=kNe0sUkNVrF2EfsS+R8FasdJyEURNbpSz5imSF1tAmsbo41n1aDzayWrL8rk8xVM+XTKLGCrQblnhOJlDJPA+ZJBpWSPsu6IdKMA98ILL+FO+7FUPeDs3Ruo9GCAHWDji0Te33fhQjAJQsuCgnVbaouC1kbLTHTAHZnlFw1uvnECBV2oXNzJlYYqQ6Cs3WviiVz6UNE7yiwAbDMEzmn1p9etYnGv6P3N7vzoRxM9n30VS5J/ZMxC3Dm3XsbJ5e1SNDTPgdvF3giCESgBSUImjR8tMiqabB90bZAuEvWruAXgYhUoLkJ8DLyAfc+FxjB3XG4B+AAeo/GNXkZSfedHqQ== 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=shf0PkL9/9+tX8AihW0X6p7w8J03sVGQV65DSX6gEZI=; b=bgx3YNnpK3q22vPje56hzHlCBPwWefAdC4fBq9ic/A6nhk9IN2Ut0/4KrV0ia9ht88M6cmpbfhn5LkPmfM2jW4WnVeBi/p2Naib5qMf3ultGX7067rJ8Mk0NBoczqDyXldbsfDo1DDwzAOzm2Fk+3J0YaUiUy70Ay8h+HatsrJE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:43:51 +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.7633.036; Mon, 10 Jun 2024 10:43:51 +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 v8 01/10] block: Pass blk_queue_get_max_sectors() a request pointer Date: Mon, 10 Jun 2024 10:43:20 +0000 Message-Id: <20240610104329.3555488-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR13CA0029.namprd13.prod.outlook.com (2603:10b6:208:160::42) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: 0bbe35ae-5e2c-4dbc-1334-08dc893a3754 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: pQhNsuAng96+4HS86xsnN07WI2deWkfqqv6VJ05JKg3bI5p0c58rS/oqLAaujMgmUz2F6q6/Q2PPfpf5Qh8DGkOyD3gTcB/U8gHXGuVNSua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SppXMEfoEaYQdgSeMZuqk0mvb/7d5Ef1A/mIRMr2XxeaQjbflbvJ2oETW7kr3/YyXsDsNLQ4RMidvnDhY+xNZhGbePH9qvMAQM6J1nOg/eYmTRGoOGWGyZhJ731d9OpCxHsh99CJvaT2TX3tw3iwSvotJzB+30B1QWnU1Od/2z8pEI3Vy5MXxHzhKSpPW0l50/keihLTa+HAywJOpL3GXwsL6Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +jSrd3OD/vSVZeS1NONC7L9B/bd/EqSiGxOeKU1TED4ZvshFMCJ3XBe0ND8Mq1oQ2JorEiUeieJb//u5+Zrlt1vCUVZtim6mQzxw0W8WuRH7hnn8GJ85jVpJ1h52SIfgFurqNp9VbFSF3u2rPK129juQNrk8GlFnQsT8YyLqHNFwxYY7hozgcfOamAL60O3MecPquJ+qMacFGiN8lR+K1bLUpyf7GrPjcqtsNeJYk3HNb/dsLllBoD0s+okZW5QX4aQJ8Xe/5wKHKJBHdV9aIXqd1mcQKlpEDam7+moNkkZJnIsdIaFwsJ2PoOSWVayhLLd+F3x0DI4tiTtVAKIIzu+APlxAj4ftJnMsKkPiSEdNcVEA89pUUkD4TMSMWwLuJjYCw+6pLoX7x/MbelHkMz9vHiSEecKekA+qTMuFlDZFkl4ZbJGK9WRoG54V/AeOtGQ0cP2SvJjCd7MKbhCoDC6QSKJCkwYsNuEEC6HoYko30VUiFWnQ2qeYHIzlnzTwFtD5HLcKtCeCLxJY7Ss6PBnIKwrqXUnVZSKPVd6x+CldDJb+Bg1toJuUJjWAlEe39iHi/Sg09brtlhgA1YrKRDGuoD4LkNBqAzKIzmKovLwQrbZ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-0: mWJWtGi3gWUC0pTdXm8IGR9jxhss26kawMDgfjuKnwAhho53r70WRDLgF81UqrfoUg5t8rVDXatH4U3ar7hLkgSGizlguCmHTOBBHTr74BeKfRh/fXWrS2gmUMhlgH2VWDUywkt5aS0NP/XcIJc1qqI3GWFVfcpan4c8sWHYfmTz+eUdI1RmoSLwJTy+zIL+EGMFonY6PQ9e/MO9efK2QVIaFYwfanEwiBJaVnBDmWjBGIH+5KlNQuwur3YtyO2Krq6D++d37EA/ll3fW4ynuLA1ulCU3R0sDLoZA3zK76UjrUkX+nCkw50JAqEvehaJDJkO++UbSwnQhkEd+3PAFmJ0GmM52fNlw57IR11R3tomPOEw5O9p1Dg9qrXPBbykgoLZhwDtPgl5gJgnwpVNeolWUWGn1c2oP9zBETMqPItftWu5JewtV+5fNMBkzLrLj5AerPsoMwrIIxErf20vsPix7MCWtlKFR3G6X5DY5bnhMNh9j90powGw7tBepYxtFyRX72rpWX52LOpol+kjyUsgQ2lUik1bXFRuifW7gqyiWHXExx1LPQ7KtirlR8JD91t/FPm3pFhATkZk0NJactFpaRUpzfih01q5lgN+iIM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0bbe35ae-5e2c-4dbc-1334-08dc893a3754 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:43:50.9891 (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: Qv11rfI0mLceuCMLaJSrbih2LIWx2jvjMdjo2WrSODQJ44OmICSU5f0ITh+8h/JVJQfFdVhGH2pbeahK25JLiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-ORIG-GUID: SBTNCTweqM2gZC7gfSrOi-7aV67-YFpJ X-Proofpoint-GUID: SBTNCTweqM2gZC7gfSrOi-7aV67-YFpJ 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 Signed-off-by: John Garry --- 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 3b4df8e5ac9e..e690b9c6afb7 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3041,7 +3041,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 189bc25beb50..75c1683fc320 100644 --- a/block/blk.h +++ b/block/blk.h @@ -181,9 +181,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 Mon Jun 10 10:43:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691857 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 D07B978C7F; Mon, 10 Jun 2024 10:44:44 +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=1718016288; cv=fail; b=J1baw8DzXDweFxh1MFD7x4rADFJGpp+UzEEuOTo5jHbuiv1HDeE5Ge1r+7hoJJsqA1AB+HklrpGX+lGlpaRsldMYxaJyh8SwoY5+WjzBFImuLgaukUWeocv6UTVz2QhKETifOrv2yn3Jm5IBX0HbH2EN/L1og35StLJntXl45Q0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016288; c=relaxed/simple; bh=2REKH1/1aH+bUNgzT8a7bGP4wBuTGd/jyvCeOusuGPI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=pm6x9uk9UZD5gm0KJTHzGQPTuY0BCMBw/Sxfq/sFs3LqZfxg10HVI1h6593Qiu6+fHYtJup7OFxzvjHUZkJWjilGGYaAkjKmb6TW75tWO+oAek6Yg4+Y/CTpBLcE9OSgLd3QVJ83oQ6JoVuCIc1dwL+B6IdSiXoZ0ZD87oqoIM4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=kW1yM6A6; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=p00unFTU; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="kW1yM6A6"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="p00unFTU" 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 45A4BPF2025193; Mon, 10 Jun 2024 10:43:55 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=Se0yQckEFgV6c0qz2c9mlgxv8OJqOdTuW+nbG+OxEhw=; b= kW1yM6A60bYOQjtf3HssMB5HtCT4Jdp7a71zF0TwUCo9nmzrUa3OTTqhRi7e0IKi MR4E3QmwEk4G25xuaNL/gzHJRqAP5eHTygTGOMp4fiWoTnntlmFGl2X6cxHerLZW HFtazfgK1woWnh60/MIpdrjm/heXZufMIP2oZsPDdPJvmov5z0d1ufZhtJUurVsK bTZo2hGaPmsjKDOrUkD55be3Q183MCSPi5w1sReAykvqkTX3aqMApMBq8jxbWb3I +Mf++68a6NtlJm0BMJhAo3X3OseSjeZIKXr5QJNVS2lTWoUD89kmI7Qf14AjwFXN eKbMZGO4c2VTnuP9sHuTGw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1gaag4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:54 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45AA37Ox020460; Mon, 10 Jun 2024 10:43:54 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncasued1-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B+Ox//Ab72Zcgw8IPcaDu8+PDh7bJeRgyPtt/rbyguahygeLi4OxzgcIEjL+W9AvhxDxe9sUH5hDAyBCOBiB2cWefBmZ2fCG8kpFTPYBPTRQCZMXJYjNm5aV4XZXM7uWV0Uc6Rf8eK3Cd+jjcn+C59FrRmN/CY+MlnM6bx8z6wUzX0Kpw20FUFLVEeIZ9GcAoCOkw5wTvkz4hUc3H2mlHnAwbFFZBWI+BRFailnrK9m+igLXEPC2hdlU2d0Q9Q7G6BBPbAyW78qN6Bnop3mCpKvqLHGHuWsuvoB+YR2HuB8J1e1DwC9UqH0h7+jdzjDYGpfQA9ewLfD03dOm37SaNw== 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=Se0yQckEFgV6c0qz2c9mlgxv8OJqOdTuW+nbG+OxEhw=; b=VygWhANcsblwvR9jSggENppq2WLccd02S9f5aZ++W2IGPpM/Ac9iHmDJg2evTbsHVJunP9YFsdPw6J0nTmjRK/XZEvrvctoNjr2BaQ/v49BeASFgoIeulUV2aA9HDKBqg2olkawzd4aDiTzdgayzgsGHsSyfGKhnnDOjMCQgZDOLyfbJA/tajBGT8OZj1UvbCCkq+Cm960W/EjYHQeQT7jLT0hm40d1WBgidKTdHD1e0Lb0A1lsN2aT/nkqCTfXrvuVs4ODwcAg5Vn0jAGpC3abd//W/SEbXgkMt3Fdgrep84onD68TCqYfzEwUX29b2/ox/5zF7853ZNVOxWrGJ5w== 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=Se0yQckEFgV6c0qz2c9mlgxv8OJqOdTuW+nbG+OxEhw=; b=p00unFTU0ewOlA1VWnxiC4X1bciIWvq/wWOcmyXAvKaHfRlizsgZMJLI3zAa37rnXYfHssvUQAAog6B8EUnDWJzbFeylKUmmMgfcJAssQPa3REUCoOrTw2Mq1ioGc8Al0fEmL+OBu81Wrlv5OaugFChZVa69p27lsAaPaLdhjyE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:43:52 +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.7633.036; Mon, 10 Jun 2024 10:43:52 +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 v8 02/10] block: Generalize chunk_sectors support as boundary support Date: Mon, 10 Jun 2024 10:43:21 +0000 Message-Id: <20240610104329.3555488-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0006.namprd03.prod.outlook.com (2603:10b6:208:32b::11) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: 04073c2e-b906-4729-a7c3-08dc893a37e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: RjEouuTsp6Q6BVZusy3spFSNHSZvLQjy2b5258Mvy/4xVneBu7QAWn5glM4AjBeqzO5SdLECmEasrfraXummgbkGLmid47EDfc51NGwENHZPuBfGl0f1npGWjSxSc/IaEB7y5+PJm4ts501i+ArbBRLYdsoimsSZRePW++EeNprVbkEhsJdrTWM0lzrbtu2JUFJAOSQ0I6Nq1kH+GUC4EZ3RY4tWLQ3IbIGkReaoxDSSCKbp3c1K8sWfn0Z54TGECyTz7pUGwFNv11MLjqzFZyp40dkneiNFKc+nwMxyGSiHiHj8LIwKTwR6m8GieOcQS2yZEy/gY5Zyb1YVXReM/viiQaht+YmjESLYZIjQzQeAzgZdu1AbfPhFovKK3wgYokuRzlEY+fmbcQGeKn50S86cLds0uTQO4lJxs435VV4J4kmVer72x4ny3iEx8AXmPlxilUtC97sgPOo4rNIbAmYmDsmCx1vrlL+LWsAB/X0ypV0IgiHrpzH9APosMHsHt9VRC+Mp5OE0GcDtMzZCe4Avt440GXvu+8rrl9evBSnITvtH008VdRKWcLOBJqlm89cY0jl6G+zT7nmmoz4AGb/vx2MZU6kGRN2c6aMQCFPL8PvmR2IDu1k0QmBOFBIHZh611IUlvNWzqQQjbTX546O1g5s7Ehunu0e3D0az249nW+N81vVErSaJoARETZMmzcgxt8yFPsN3PbJSIeak6WH6K8fB5dRlR7+llpQ1aQiy+PCXot13ICU87xHhXiQ2Sc/SrOrGBJXuE1kwGpZXeqmfRq9/3vONKhv2G/jFBxiyTZ3Qeazd+/+QrmrP/AV/siaR/x7J3Mdelzou9AzrNmqSa1DksrmMoPLthkc7LcNyLEJjvkc7h6+K+yJQw+nT/65a1UOHA2sAOXAXziIScVQyxqXkFHrCExWnTMxCvbeU0eFBzx2l2FZZz7OEMRapg/PB7u158t5DcgUk8pWM5ZYhFiRYisu9Aq/YBrYQ26V2x/9OMyEMsk7eKU3s+Hyr3Mt/LhDGtmCf/Qe2gwG6bwkf8a6SgbLRwfjvyFG9rzY3GfSMHyezUq6AeDbhFrskzwxoDtbC6Tpegroc394HPuU5Vl3CZBX0ShUZ8qLR90aREam0xeGEW+utfzY8jjjLku2f2AOdTC3z5KCylmcWVwfQalJh5LWfz0c3GSINF5rkksCZN56SserUxPnP/oy+x6VeObezNVVdt1Cz72b/rjyU8XYtYnwplpwdmdSzZPgOJwnrbZgIiSw/dPCyOdYAwz21WoQBgUc9wfyBbw1C84TqwEeRP4rrmV88Eq2dpAjFwjt5YQ7ph4z4304lzb1zPe0BxsK+7uyfJt91H8NKK7T6tsyOdOnUCwT7RUWggAI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7l+1CBgcHJ9vJa741CYlh6mMblzCdnzncYxYZQ3iOVjElva/EEl96hLH4wySzVzzDgE4E9GtTyZe6XHvYywNhY5RlCDezhbEa+VePDoO/P9s5Eqx9Tkgl6GY54CiDg7z+STDlaZsB6ep13dAipLCqgE3z1MWOHKofpxE3vFTr6kfx2AGZ2dZ+qK/fpyGo/Pfn9N9vEKgTtIK9iPPj4tpCdgawhg1sg9qGuAWmi5YLy78KXrk/4DxP1HAFPrS4te8c7YP/sz/RorS7ugZNM1pUlUqYFdBW6pDrp6n3tnDaROQIeQB9LhHAMxuD5fwiqqjkL1l5kVqktP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3Nj8wr4kxmWVS4ylq9TbE37RM5eOWiAf/LJlC+2Eqk4yUFKI6wwqZsLM+B8cQm1E3E8EVf57/1VbF926i0pdsBzCsKJZ2SYA+geR6f+HjBSdGBu13sO2RcMkfmaxAw55Fh1tGs7hkmxOSRX+16p2bDRIlxJhOXBJwbKo+lx8uFCZNDJalR5NIw7l+a+QvRDbq9vfuCh633GuK7GZFw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: HvGP5XZ5G/fNaSmWb2PBPkDgq/H7ELydxHL4O499H0l4Cv2ItmDBZobfBSR6LuXyBbvp8PKrXfOSLRH4PpElu5Nlls6k21HnsIlzEkinDL8Xd3TC58oABa+6DUGB7RLDUf7yQWjo4L35RsoDCjpSzJNvVFhOY/KEnrvuDo8nFCWol5FG40CVU5nx/Bi0ql52hJxfumeKAn3hZGUewRFSyxwgMB8u/EcvVWMivq8h/cfK7+QfCj68PJ7bdjexTxU+daG0I1RYUkf9oa30UwRn3Mv9fr7l+LeABpuxyTtG1xWL6gAPLNhRyEVz08TlfjsiJTpaCdAGTkfSbefynD2bFlX3fv1Z8tODOx/HyQCWNDydEtEqqpNwijEnsUnSAnal28PnVAMGnoURAX/qNmtHdKxkmkKcUeHx/JsExTdCGAUT6HHNkxPwFz1sa6ffnR7D1DO4yJAKZQ2U+nbXGjp3GcIFFOnCCZ5Ssb/msllW0Zl9CYBILpE1wrtcn4jl6VPMgZkIR3qAWiaz5VZ62wEWn9U7rBoD5h6WTfo4fLDp9MplEreuoZrGNzZhjqdnFEI0QyotqFj6A7QKNjA39upIv7oKiADjp4sAO8S/aOj1PlA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04073c2e-b906-4729-a7c3-08dc893a37e2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:43:51.9969 (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: 0Siuw/y8FIFlD1NJmZZFs66++Q62kDMJu2GFncg2BE6NtKh69bfuVq4fDHwJ8kV3XhZJytIdI3GiijgcOL4Xdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-ORIG-GUID: 1t_bsR_n6Mlcw1PlpQzuYtZZMV80vz5K X-Proofpoint-GUID: 1t_bsR_n6Mlcw1PlpQzuYtZZMV80vz5K 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. Signed-off-by: John Garry --- 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 13037d6a6f62..b648253c2300 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 ac8e0cb2353a..ddff90766f9f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -866,14 +866,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 Mon Jun 10 10:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691854 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 439877D08F; Mon, 10 Jun 2024 10:44:44 +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=1718016286; cv=fail; b=n2SSUILJLCKZFpmai+cTq8VccU71ORWEtYKHpmSm2x2Z1VDS9jHRY9KVs63e+fLPATt7hAEwRTnOSBiNKKOR5X+3/AwhpYYQTVME10tmOuxN/NpDOwyOgLwtzRvedUWJUYPA6qhaglUk85+1I93vIfDFfpvhKMv4El6tA7p3zow= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016286; c=relaxed/simple; bh=EGk9YcHxjcmZilKfGPFTkymr8vlgyBhAc7MPLlD3E1Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=uldkpIfZbJa68zuxmSYXTnccZA1oIEbkajK11FMNATbN6b2H+wX0B1/Ht1ki55xQiSpdNJpdEhqmKJGDQHCn3xzeaGKCCM+aNpQ4nIdBkqhHXYExN+jsKjVnZesMPo2v8cNoZv6FoemWdLZTUJBxGirNrbgv+l2KYRs+JaZAFQA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=e3dfueCG; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=TWxxxSm8; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="e3dfueCG"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="TWxxxSm8" 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 45A4CxBa027095; Mon, 10 Jun 2024 10:43:57 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=o4M53ZUAEJG9jj6Zs1sWMLUGMl7ET22Sv5RjhoHAXkA=; b= e3dfueCG3fHnyDSYkGZc7RWGgzoqPYn815brv6m4O6EkZc5EBLKemiNoe8qRmh7Q VinasocQOHjYDKzG+wwoe+p3RQ+LB9PWISAH+Ozq+4pCuSg6xbIPd2yfvvxCMPfZ cWKV/xmyJcCQm4A4Tb32OWjy0LcAoMLFium8PG3cEYNVHvzk/YZJrUCUaHY/GAnw iiOHOubtizW0c2ftXZoUv4Q99WfYzAuuDh7qwSuYUGYZ9jSlUCCoeqMTk/ukGJbR YgPvEx/MSNHSrXp/Qt4R+ubIB9D7ZJOk3EqhCW8v4bHT9Crm+3nW9nfUqJmIZz06 PscqmHdSbDYahAdvKKNM0w== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1ma9w2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:57 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45AA76t2021119; Mon, 10 Jun 2024 10:43:56 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncasuedp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TzcO7OFXdh+vWcw61ZSlUTJEl5mYAAD5hgFLc29e6CGd2yP4YuUkEAmkkUZX5ot6NS9qYS232a46tsLo0mQ8n4Ykgdd0ZhuoxPls87C0z8mPZ/62TCxTo8YoIylHq4acmgR0voTsb1aE2mXmL05p9OlJHcC3US0YZOOdQSxJDuFQMQBS9FI6Dd3a2g0C/aWFeesE6giTj+6Bekg8wtvVfd5SxhEzI8sb2hguRy8SM7oE/xfkvr1/7gMBhlMC8anf53UzvAbb3KsYrpiKzDnfupkIi1optXa/l6CI5htqAfbUqvnMtaduNxhE625LtgJXzbNzL63/Yk7bYLKQjJOUcw== 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=o4M53ZUAEJG9jj6Zs1sWMLUGMl7ET22Sv5RjhoHAXkA=; b=iVPWc6mHhPggFFVelErbw4jMbhqI+2C1cXF/AYxHU1T11lFqyCe9jc/hF8FsV+mqFKvM7rBpQEoG594FJOaTCYyBjG19gxLREN466EyQt2igN1B57ye9cFDIERgCViVp2CEuQGT4+uIsvcDjBhNb3JIGVGwmesQp+eOuOQeqVPGUJ4spjctTsU8Qf7RI0YXfrZMj51XUT22z4RaKV6iPXaP7wzYd+rQBaimDfhsP9CBsGdoDfvKafPgpxobLEsrNqAWd6nSU2a/JpPPKEp8onlRMwShvXSx68suEZaUUvXeGafHcgL47H0SEEsFDnZAqXta+BeDfUu/OWj1Yu2Vj6g== 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=o4M53ZUAEJG9jj6Zs1sWMLUGMl7ET22Sv5RjhoHAXkA=; b=TWxxxSm8DPuF9fMpJ0qncB8B3IV/ubkTsKHjDGoUjJt6E+iOcV9zVXou9lnakb0IVH7rrjIPkteoWR1D7HahIILJsW1bEPYDaWYRP5Av+pOjzjMGFmdfTa1yEP7wa3AYJ/XkLjFVmMas5uEdDP4FtYmg8ES8/WF68r1yHaDh4lQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:43:54 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7633.036; Mon, 10 Jun 2024 10:43:53 +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 v8 03/10] fs: Initial atomic write support Date: Mon, 10 Jun 2024 10:43:22 +0000 Message-Id: <20240610104329.3555488-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR13CA0022.namprd13.prod.outlook.com (2603:10b6:208:160::35) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: f617c6fe-eb5e-4085-ae09-08dc893a3909 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: 4vsO4lbz8gUFyV+TD4jCt7zCbMslj+SRT+DNhUNF/LxaN0Qfe8KzF2jR7TEqLDbJGD6t5Ev5YfOK/xZkPmWmclHljG1xCKeGdYXYQ3HWCizJDYbu/YCs8DvxMsjnGJf+ZbCZoWj6/Oy+qNgh5j1j/pW50uPYHmrs1xL/lCat7yqIKGLHBCwF7785MX7dvsJSD2VDeI5qlbH/lUawr/vNDCfQS/tAGu5V8KI6GNO8/3oqSiEuTPWy416RkfphXeiNAch6kJj2Mj6HgJxGqNJfd6hZlJ25zuEknAywmHpkDDvKrMD0s0xcvQ4dHvbnVf1uPSfOiUjzSLl1Yyk8jPMmWqHyLnwBc/ckvZblMKBBVXIDJhPIlDDN2g9JSwK8Nr6KVC/NczrtKjX8CpwJNndddjxqKPfjJAZbrEUxGue1Jt9gijYq/05ZS6rM7Q9qLpxt04YYttWmn90vysAfnJXdJ/vV66Eyp+lpwtSIN4tU2svI95h2q973+n2cVL0ppDTe1YRkmn1BdjzmuKU3VghS5x1ip1iqMane4VZOn5K8X7QUJoQH7Lv0sT0FwS+dca4yQ4z05KVM4IUZ5NUtC6T2c/fL1Z70cQ8vYej0JChhhRvI4sl/rG5aiIuP7fjEVdKfVhDXXVVib0pi8o4rzmul/wL2IWx0uxlOxtnxdpJct7OabJ1PJVo2tlShZOcmSiKru2XDYUuiWvvK7nB4FR2kqOkCyAkhC6T4IqFPNh25UMrYWeN4gxSc0Ouy5lL9FPEqftaKt6ktY6F8/OBM/S17y9veA+TVN7SP2x8ft1odzpJrjHTAp1hqm3+cpwdKhuY86BSFy2gfL7RMgXjV1izKbXnA3mBO5e+xTOuzhbDl1BwGFtYxtmbTUQc4iMHq9P2K99dgBAx4N4A0TW8QG44WXs5ppGl1lTFJPVfXgKpfZx8VzWDkyupIDWHB8iGIwvKqdh41zQx8E4B1TT5HN6Jp61Kqw6N3wjEqGWgPIEmppXBjFjfm+ZjKb9Yvtpacvj5DFtLDBJX9oxLoisbxRncrxcOTfdbXeP2/O4k2M7J5PSbndy4eiUc3+b+K3vQrzV/NMcsVO/PyZawFH1yikjVuZbuRbH1wdy2wn4R1sv/7Vdx5RlKKhliP5kq60hw1WDhaEUniLTR5DH+FkYXG/ZW5hUCUcrra8ndWHQDGBRdai7rcYdM/5mp6A5041p1+YJWZcwD0i8B32MpbsaTfFbb77r4Y3tAZFoGn/GEDOZ2KIjmfRTuH/HaHJOOBvwmRRKGvbmp0kaSYXnWgxj3Tc9Zv72pVK3yILWF17wnXlKmtZnY/a5ozLahjzoWZ8Kj4SQGm5CJ7lg1c1Lctv2BI++8vcayfyfq7cBhr2e1BwxKYyuc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BKfz2t3gGuUo0CJ1s5qlR5AHlnpOqc3HXSKdsZKChhd6vNz93Uu2sj1EfxmwcaELI9AFOiolrwpprRvJyUdAfJjfkp2ZVeJQxy4XaFE5XVcFBRTT7N9/K3xsZbf/FIicaQHPhsqKwsovPD0H3Yz55Vs23zMMM9YoExx6jRuEEsp25iudEXiFCdSU/If66Uv5rdh+HmePVNetMEDNNG4bRPJl+jVIXK9E03/+/Z9D7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QnFdOeHJd5Ipol8DiXN+11iScMrskyNik0batsMOmrQuzCJ1fDpCOPd4utoN5WrG2vHmB2ZXA4kMirvUbUzDAaGGTuPgS5OGgVhimVfA1/HDyXTRT26na3a4hRpy4VvNMYuw86J9GPgjr/3SsL13UOMKvWzSIrxmAWNpMh4624mfZ51GRewZk7zAs/Q8/FRiEY9hCRn+ukKcCdocMw4uwTG/renPBYHG/No+q55As0MxAW9+f+tftoX94qJ2Bw3i2LBDySS3faMjXnpmHbyQF8vSGZj6rikWGmeAR0FzGpg9NKrFQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /ZllUAGv52aNpYeUFolpyl3JSYUgipBf8OGp/lzpRkPqraCSwc+ShT2pGKoc4u1jMa0KUnKv82P+M59Cea83zzkk+6DUtM51Gd6ci1LHnEA8Q4EABUqoCmGWdbelmROEhN9YRqC9KD/xXCorwqvGbt31IWJggM/HgWhIX6Hmgs/NsudbJR51pW3avqa1QDCotwkuUImPyCw69q2u3XYC77AsMUxAC60fQJcM1e8PNRrztVv9wbZVKwPmQu4QkwEY7bpWrZH8oLjYz9akp4+u0ZmFFB8mVkZ0Fss4IJaEOGSwsMt9zvcXSXAaptA1XkVur22h2FOF4KQi3VBKujHCigFqxqSczpQbDl/UjYpeFqGAFV2etVyaqOPu7aOL50WSkYE88XFCr+DEH5mbyG/NJzrvBQFVtSVt9WnU0Ar26QtfN31aD2ub1nMMNcfnJEQF1pN64gUKqUHc8AqVK3BFOJ/CWqZ5ENlkPaG70ck6WOAG3yNDMn5MkGJZAmqDPMj+E8ZKiteba15dEnS6H1TI2E+ujeD5mgx1kbcQZQ78dAx3mkaJPccEQAgJ5AqvTwLYst5VkoR7p9iyxtA0i69uxkyqdtW97M2F59EtUplRmGY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f617c6fe-eb5e-4085-ae09-08dc893a3909 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:43:53.8625 (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: lOWZYKTlFsZZUp2mHAmefSsh+5Ou5nPASWuXJ1YTqRbeaEnHE4tjDpfkz5dqRyXaoU8QgD8n20nnEo8IcEUN+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-ORIG-GUID: HFAEe8-QM4BRrzaq-KJ0jAHwPZguQq1g X-Proofpoint-GUID: HFAEe8-QM4BRrzaq-KJ0jAHwPZguQq1g 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 Signed-off-by: John Garry Acked-by: Darrick J. Wong --- 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..285b0f5a9a9c 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; +} \ No newline at end of file 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 Mon Jun 10 10:43:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691861 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 E4640139563; Mon, 10 Jun 2024 10:44:53 +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=1718016295; cv=fail; b=PHagimgTZnRRxRrjK3xxSjd1n9OyXvE1RLwKJiI8nEhHq4GBBN3VBPJuHpPEmLH+MxtJmXDLgC+MMMNa53nUKg9GcNmrODW4NNaeNBcqFvOtSlMWaNIptt5CFi7vAvHI01+BhCJVu3d4rvq5UIQZCb1rEKGxVCCSUz1SCeY6ywk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016295; c=relaxed/simple; bh=5/bFNX2HlMfsKCpFbHV8K1O9l2Ek5stP7KrzYC8R7Bw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=mRf+QvGjp37/M3h0vl0wiV16VX7zbWzWrwsBLMPDPY5QtNLrFH+c4JvnWI1PIWfGyvCW1qduWdfP/QZwMlHCpCcDTDNfxPPqwdorl+4ODOQICnTMxaD8pvyE6JtVxrAs2fbIBV0KTI/qbrYME3SH46h5/nJXV58TvW4ZTSi81UM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=hTNc+YEW; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=gORaHUzQ; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="hTNc+YEW"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="gORaHUzQ" 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 45A4BSKj006761; Mon, 10 Jun 2024 10:44:00 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=TbanG9OOchDY9/z2mDu4fqQnev6OFwdKu+Z6IOGBWmw=; b= hTNc+YEWRRa5w+ibiHckZif9bzmWjXAw8QpH8zn/GDelgGgwqrF3l56Bk1O4ZYuM AkYsRZqSznoc4I3Sb/5u098zNTqgWfGGWonNcTXzxaV1RU/pMx+edCI0xh6AWFfp 8LI7EN2ovFc2WiHOfd1Wf2uYgl/V3vesLT00YBXr6Zpky7bvzSgVf36UuyHW91nj 7OVf4Q+xIkQXfPXQ81ULzcojzSI/xN53mKnACSqKt1ZcE9eeXeRLHUMZ+gtiqgS1 bhC7uG1KdFpF09SrtwZY/m9HkV4CzPPhU8x1Zvb0uE7lovogNSrhLZbTfJox052S rH/FuzW8/v4JafNwVoCWNA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymhf1a8t2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:59 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45A9B996012520; Mon, 10 Jun 2024 10:43:59 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ync9v4sck-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:43:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SaAyLgYSHuwYp5DkVuxDT9xBJjiChgdGTIkPUglvEMh90V9IUhJcYukzjmwfA1ZQu1OeGxzvQs8ZPBo4e54Yk5OqB5JP4JklIUvTz/kcI4fws8zeHAJs2Tdz2xhMZsyPWt4Y/GUtnFk5+8Xzd0ht8eJEerFfRlN/2QpUcOzWAhcY/LJTkMSj9MK5buez8j9XthiRJvnYkMG7MMaaftaFm8dcnXNhe67IOFfSkq8Q6CCvUkSXEMz+IGwDw09ITEGR3zMadikLXIS0h1+xWmUZIfYgATz7/ENnUbeL3nIcKCSjQEWTcmOQUrbIZDrI76E2m3pCeK0C3a4HACJ9LtJQIQ== 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=TbanG9OOchDY9/z2mDu4fqQnev6OFwdKu+Z6IOGBWmw=; b=ntqVOn09St3essbzi/Soxpn+Wc45TENCokWQU+r6Qn0Yc/Z29RWz6rClf0wD8h0TrB7l+X7Vr5hXJTDH2fvsU3wiwCeofSNMRvvIU68iuWtdSRMjkz/WAsJS0PYnyTRAV8lKgoa+eltOhuOthxSuscMddZAUHtH9l3vkPlPopOjmNOlOg7jM0Rkz2QmS3ykNnxlLfjutnKYsfnOTxjoMk6crfOvgGPYXIA5NT07/1QK3O2CxLSt4fT5Ak+bMIbsdzhsLonx9DYDICrz5uKh5v+7ilEZkMOVUUTKpsEtO7BxTv0rGXQSFk4R00McO10VhKj5lbt0pS1SzXbUh3/2IuQ== 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=TbanG9OOchDY9/z2mDu4fqQnev6OFwdKu+Z6IOGBWmw=; b=gORaHUzQU/DNUE+ieKs/4w57DNpK7/5ocK/M/NLWdixeTzwt5eIcbztLS8qTUnhfzOMPSFoElL+EEtS9TjZF+DVlon4L871y1O0/93H8S7MPKaQRzcN3QQSEK+parl1rZEo4LuUhQ+Unz/Ocv/0HAWLTcLf+eY6T5p6n/Zdq38o= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:43:56 +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.7633.036; Mon, 10 Jun 2024 10:43:56 +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 v8 04/10] fs: Add initial atomic write support info to statx Date: Mon, 10 Jun 2024 10:43:23 +0000 Message-Id: <20240610104329.3555488-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR05CA0021.namprd05.prod.outlook.com (2603:10b6:208:c0::34) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: 327340ad-2578-4670-26f1-08dc893a3a8d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: udMSq2L4Spl8FLgcn48LMRU/m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KlZiUZkcYXrVss8xcKqR5CtTV4M5ej8EdhhSmAJYlougQbudRidNQDWtSfqVxzTkHExsqQyQdg1N4XNGzpsQEMb7qVoOBBfzjPJbTwyFzvA+bmBxQV1FQDmgPyD3ZzRWXmht62w+u3nQCH7nBH0NSRUOTZSW3D5tGyvTiIOALEAhF87FCO+M2VBxDmZQEmWKNmd3kO6/DwB0nkwOg0SC0GLz94fRc/lHdeVX4O6pMyXMSJ8PYYjKlCDjeY1QHytKvD8ol8NRO4iiVJ4wENoGkXzZppX/3p9eC7R5UUc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RL6yRYF6O+qBEyJi2Oox0sDfNeFga5mSK3mIa1IDtGhBNYlUHef/H7oRTWIMGAjPKu0DUI3Dyhj0XeQgFNglekE3ydqfzZQGasC9A0lH9eH+6jUHafiB5Pe9kGnqF8z0c9bK3o3WoqfEHyru+wkBcWXuMw42xlTXL3b/Lwrxv8JVVeZbaKmiNjFQLDbHkqDouOErMd+a7kkRL/osmeG3IMuv3jyWFlwHOxO8CuRQfiVVmSARo3w6fbzCu9lKRXkLWODIdyZh80T7q1WQRTSLXVOR5w+a5FogQOI/TTh6PcyiIfMO3o+2PYEQneQdHJ3yxioynb69H/2kjyH6UCTUnJ6zo7wxAiiG2kNc+eeOUAPfBI61nGrKv9NTJFuq6v1tmvjiWDIlIcbsNOtrhJGo3HXWcp9PApu3mMTi85MKCbHsk0iYYwaOyiGfdVPwxt7oB4BvvTleCFFJE4fWKyM69l40T6WohyNu/Iuf0bEJsTnnelbm3dMsm7WMS7S9NWSpW/gWPE98q2SCCVtReXdHy08+3nilIoFLXoQkpkuiJh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change-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: teLK+IZRo8KTFXeimExTqs5v5Qh+xK6VoESFpiZ22k0p+s4B9xnqsNyNT3xzMi5l/tjQ/ri42o/2BRJw0wqJEMQUVsv1TwmENxxaXYqaZY1vatvVdc2/vRm2C0DUU33dB0ZT83ErkZTRc7uY7t5pyQKmevZsXG/kuBDT1Awxixsi6oXMXgZAHC/jUgWzHbWuUso/CZsSDsGBmoXtXBF+MgSXbxL3aROuJmGRy7NWieH0RpZWvcJox+yDfHhT22VRLSgzLt260nIppYhEWXyU0zay2qeyRhAz5agEUu+gYT3evCU+4ghoTcOQMPZHEiPI96YPQRq5P3XZ2v4Nfx8NqXs1lRaOF5LBm01GXNraPGyz0Xrc9g93Uy/CbRVIh/pkbhQj8X9FiaS4m/hRU1ajUfVdJLDLjvkGz9eG3WRO9ySSkCqbFS7sz/gtkiE6CPQO4ENd937mJDPxJ6M7tpVr2u7o3+YvnarFye+1esliV61J0n2nxbS3VhgKm5o07mQ/gfe2QD2PThH0dYjMG++SN3GB6t1sZ/8Wn0pujHyEikNSWELLSOEBjbpuMh5i96Aem0OpW4B09fA44JckdJ9PcJ1HBKszFHLPRZmuaUNR5d0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 327340ad-2578-4670-26f1-08dc893a3a8d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:43:56.4028 (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: MPjDJFY6fKO/kVjvju266VHeqxxCTppwBNf80uBfh+znxx+ajV+BtNUpwJK+BWzHYIjb+EwSmEpxjmlGlupfzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-ORIG-GUID: iPsZLLU9F9r-Pjjtoe1J9zvg5zuBshN_ X-Proofpoint-GUID: iPsZLLU9F9r-Pjjtoe1J9zvg5zuBshN_ 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 Signed-off-by: John Garry Reviewed-by: Darrick J. Wong --- 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 Mon Jun 10 10:43:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691863 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 B5E5C74050; Mon, 10 Jun 2024 10:45:48 +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=1718016350; cv=fail; b=E/ehiFgCAH08o9cQ5ELjF+0OQVF1SFtmpiPqc4AqzXwrJ+p9MIzxfNlsnACwneIaVv15CXCv9qnLNJ1PsU4Kg6kVox2VhYv3kgf4sMqqLzogC5WnIURkJVC1/rsZyBH7tNDzF9MmdOyeow7fOia5IOgdUJTx1GLRxsT62k+BTMI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016350; c=relaxed/simple; bh=oAIBUPpDmv4JGETOqU/J3N8jaTg97+qKD8BZM4pEZdM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=iqksWifKzLEvSL2yk+Voo6mKVYf9R31J14B/obABx5GYQN9t7azH/g8YntYhF+y5d7ZS6gzE4Qw/fnQmZKb56es9GYwaUq2+QyKaHMVpDqueQli/C8D4cvGgvYqsp9Q9XfwX5+jw0HQpvbpNtHgSVgvT2fOtMt9mBV0YErLnjMA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=k7O73Ud5; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=ya3EEuRy; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="k7O73Ud5"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ya3EEuRy" 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 45A4Bqiq025709; Mon, 10 Jun 2024 10:44:01 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=uHVeKuD2AEcCqZ/LjV+OOc1QBnsCnYX2OlH3aXiQ9Bc=; b= k7O73Ud5D5UymaRohv7hH33qchVmM6XMbJwRMW6Yp3Si1VaRpOEY47GkLuPkar6N Ku/btK31DN8kvCh0833FcwSvxvfIb4dhjYY8BDl2bMZrb9qtoplXUuVV24Ql9vzF 2jq9zcSJpDyExLihNY0VoU1r9CtrFQ/gcRiNA2PfcX8pjY8XKVyFqCriMltOgZl4 fwJg0cEEnNcuplWcNpyFGg4ReuLgAIx8YBHnoPL2BUGm9JYAv1TDTlxNz5HBE52R O3k3TXf4OWaIGv1WqThyDIv8ctTxI0ADyk1y2yhci2EQ3M0gLkSVFEsqghdT0mDY n1mm0I3FV+DpqJkrfTF9RQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1gaagk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:01 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45A9uGuT036740; Mon, 10 Jun 2024 10:44:01 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncdukche-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E/NtkekJVgygCkHqp4AWHbhg6w5dulguFIgxuxhDTheNkkiXqbgk1sD6QBBcH7eMcyAiLweQUd7Hor22P5b2B3AP5ggxIYQ/T22qMFR2i4zzzAYjrmCO8nOVNZByMUfyKjT//aJJk8qNEPd3yAN0/Pd2LtaeJ9KLDtZJVN6DVEi1wgPIozMpc8y3KH6ezhfKy2QBiZiJhEmkDXzT2aNBb1dmehbBvpcjkDk7MieYLwgZ6b5adiDvgXjbat0TRK1Bct81GuA8xVdHyya7fzuuJpMStZKmSiqx3MShbGVe96m3o/3zMJfh5WUUky2Y42ccOnRa9nRYg0Zu5bwR2a4q8A== 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=uHVeKuD2AEcCqZ/LjV+OOc1QBnsCnYX2OlH3aXiQ9Bc=; b=YldVa0ymUWbbeKxGOlEZJ44eKlW3hoYIuA/U/CQ1bBE/jwsZKUrCn5scpMst4DCLrzH/uJuzbUocIXx2Gu5kq0NH3B2n/ddqQEoahwwwfpY0RrTSu65Yffc3WwY5gxEGlB+6fEpbznhOnmYO2FV8nzEfsHvyF+pmaLf/pOf2vDEhrSag/MjrpPa6C6kIEkGViHd3eeIfNLN1SrFPntgmmI4qczf2B2m1/hrozre1TgNkjTd6x8m0FSG7NpPhjve79edj4gCBDbqxiwvvfyQyAOScWe8psPI6lnAS2vMlyizg2OHtzPMqP+0Bsv21WaPB78z+Y+x6w0+SFLcrqnklGg== 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=uHVeKuD2AEcCqZ/LjV+OOc1QBnsCnYX2OlH3aXiQ9Bc=; b=ya3EEuRyK43c0v1NocjcOPGjb3Ppsr9iihjwKjL/CLNe5r7XZLSRJrDQhRNyy/5nP/7xcSwJG3qypcPY94A/t1NbGJ411IWcVJupAEk/8FvmSHdABlEK1yru9hCYLAiiDFIuaFdUFRqmUsVxyVAjgvXKUz+ZTjrBGLy/LW5DD6I= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:43:58 +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.7633.036; Mon, 10 Jun 2024 10:43:58 +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 v8 05/10] block: Add core atomic write support Date: Mon, 10 Jun 2024 10:43:24 +0000 Message-Id: <20240610104329.3555488-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0260.namprd13.prod.outlook.com (2603:10b6:208:2ba::25) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: bd5ef50e-30ad-4032-b292-08dc893a3b7d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: TZvYyjQSHEgxC51mVeIgYTJ/YAeXuoPjNbK6Q4X6hZfC9fufQIJS+w3afkRTCdClxAVBVwTLNVj0Fg0tpWuIGzIexUVyTsovXr75dC0/1XedpzZEGpEmFsvNSWnSnRt1HT5p/r9r3uNyofsyS7X4jVXZxFaS+gfGQBZtVsg7iXy8GtcGY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ou3NQZDNAydg+nkRzbc8tyQri8dXxGFY7KOc13DfRjW1mJOWhYKmOAdShps4KZXo9jT9zx6cO57INYiYy6V9NZ4NQO1xlBgjKwAZ0XW72HFiPIhdcAehn7+7mk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YJSry7v0xGVqisuwbI48iSbswyMs77XSdr+B9ysLEjImSOKxHYYdrx6+2XCKJoXEHmKGWnqgnIhYejuVSU8GT3wrUfMZEa86LzrYbSo+59Wjufjo3P3DkHxhx93qeAGwlZaYyFiUHMtH/G1s2rJO+ZAuXXMtjwDZpuMr2xey/hVuDT6+T5dsBrfmj/M6itKlzGXmIK1wJhaGxqi7JcUMaEYDnttyz3zJqDBCNGf+p/sUYSJYcg4LW7muim2e8OqXDEUJtvUgI9nrcFHVgpwD+ocnhQ2j7CMXPFZiouOPqo62G212u4Mjeai/pxLUtdQGD8Mu6zYk1n94YY79u60MdwOjn7WMQvrHmorRIZfomFarZxIC/Yl0ar8aeM9REnQeSYxjwoq7BUx0WXQ62fSRt1RBJGS8sQosMokiSu3eMENV2Xpu1ncYxAX8akAYxNglb2J+vE3pXz2PYIorKUa57nj+ti1LKQvZC3iFw0IyCID+9M5w+amqRpTGg0Uf8Rt3zERbjr1Fq40E9M+6tneV12VGxEFGbpLNGqhpfpw13nIqrkWf0i4FERN78zoyJE03iWGH0H65jlXItRlJ23Su2AukCHJK/hCu3Foro0uqzczgT9zl3KMHNZfKcATDHtBOz2+lhor9DE8lqFiNlGNflZxGfJbq3bhaJHbc51ZW8ta7eBowDMDYt/tZht//uOk+oeH4rs610NR+ZZJiNo35cVcPO5qRI04uvG+5+L01PX91DqrohTMofiNkY4QrV3gLbos0o+27/6c9g2K0yMHpH3nivFvtFcbL7LzUF34xpZiFRHSc7JBWL9BdoVu3szwVm+ao36pfuYw6S1lq/0yNBHObRL1TpkGChOyUBFvjYdKpYLmfOJhaRqidLZmb5rIaI6I+Rz6UfqlCIhQNt8Y7icTAVEB3lgJ1aVjEuU3XgwQuLHnGlrygtl/Z9JTxybykNNu2vNV4uRaNr+/CJ1tEskDYIebIu4Hdz/7F1I+OZ9mW8ylh5YNJ7xgyqa5gKgnRZFwYM99jwZHsy2jpDQUnmkCeA/6veeKr4nlWZANswe+kbA2pfsIWvMPOoxaiQ7IeorZRw/tD+YLtfb0zwaaZgHBSmWBT+ZvnMofVZ9TZ95w9SWUcsmiPTzgFq7R9HADiRaYn/Nw0Yl43qDznv/8Nm8oDqDds5bpmvffFbsgeEEs4etYf6TTiWBNV+BB8WoCnvin4C+xCKiL4vokzsfKSg+6x6hberYcwevyCkhdiVLA9ackGn4COkI/Lou5/UTMNquIBaLg9e68SKP7uEZKPnlheDKBawxoQ0dR5iAL9JXxGdCPvS4llKd4ZenRskv6GdWH+mnTJee9t3RY5xKkwYBYC1rqtMofBLnla6tnmpzqVu9hqb0Qxo5CzSsrG5tIxjg237/g5gTTozv34AyOW+g24lfb7vGuqqji+H0q7shTti995y4AebsxdHWYtdvMJrkiGI/fgCMRMrlPxhqOd/kON+UJVIID2RZDSedfqUHopKl02io47EWouM9NlaOJYvSO6OJM8LdaGURzzvlzYu//OoeQpmvLVV1RRD/bo6jkhnpdgbC6QEa5PX1FX1HqY4R4nzD88SH8D4u6n4Oe1ng== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: YgeACnVvN0bf280Haw4oLWtrJUMGmwarO0WxRqbe0i0BGZREoBcbhDUnov8gRyUrwy0sVVoXdazFCam/oBR8N80qxKj+N90/pDGDheEG5hT/fsOdOMZ5muVUl6hRSfMCYTtON5XckOxUY/tvJBwIq/xI9mKnVQxif+dWhoIwix8CV0/bJAjTpuG+xYKTpqPXiXvx3wbmd2EngsN8icPDEdSgSCtt1b9+Jfn4G8dATucRQsN6+wKW2aZb4XYbrMzHzFwy7BqMvPu7zh/2WvoOzGdVMzQRlnTzK94NtskRa27oi7C9/dtdF5DfD4mXgZlNG3d6Wcgac77j81a9tXb65wDfvkDovSx7NJKWSofiAXoxmTENDp6MkumKnv7b/WS5hkBDCeARwRhSNITKXVZ1URuLHp/q5VV4rn6LQKTRKVTsZOLcADAEbH7B48NapRfj+zAGiURbX/DhbuwP+Grv21aeSF0hBZJWZSlpa4tUqHKnJywRB/wiqOktpFdgkYFOtlPfiCqIVmyJtu5X6fcCoo92zyja1Vg2XXP8d6PEZ7k4alDw5aOo36gUrmbmD+pG+niBBUkLT4No6Jz+k2aEjoQyxnpv3eerKOXF0Vxc+I0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd5ef50e-30ad-4032-b292-08dc893a3b7d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:43:58.0600 (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: P342nQXQ8gY425pPQDfGV0B6cl6l5fX7e+CbGWlEnuv1uCGrlvBn9GN3ShsMNA75RFkiEEGLYWjZsgCZ5ZevcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-ORIG-GUID: JFo0uzMO69HIN5WjqhJRck976ags3LPo X-Proofpoint-GUID: JFo0uzMO69HIN5WjqhJRck976ags3LPo 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 Signed-off-by: John Garry --- Documentation/ABI/stable/sysfs-block | 53 ++++++++++++++++++++ block/blk-core.c | 19 +++++++ block/blk-merge.c | 50 +++++++++++++++++-- block/blk-settings.c | 75 ++++++++++++++++++++++++++++ block/blk-sysfs.c | 33 ++++++++++++ block/blk.h | 3 ++ include/linux/blk_types.h | 8 ++- include/linux/blkdev.h | 55 ++++++++++++++++++++ 8 files changed, 291 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 82c3ae22d76d..d9f58fe71758 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..b158d31940d1 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) { + /* + * If chunk_sectors and atomic_write_boundary_sectors are both set, + * then they must be equal. + */ + if (is_atomic) + 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 996f247fc98e..140e13616462 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -97,6 +97,79 @@ static int blk_validate_zoned_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 boundary_sectors_hw; + + if (!lim->atomic_write_hw_max) + goto unsupported; + + boundary_sectors_hw = lim->atomic_write_hw_boundary >> SECTOR_SHIFT; + + if (boundary_sectors_hw) { + /* It doesn't make sense to allow different non-zero values */ + if (lim->chunk_sectors && + lim->chunk_sectors != boundary_sectors_hw) + 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 be reduced so that + * it is compliant with a !power-of-2 boundary. + */ + if (!is_power_of_2(lim->atomic_write_hw_boundary)) + 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. @@ -230,6 +303,8 @@ static int blk_validate_limits(struct queue_limits *lim) lim->misaligned = 0; } + blk_validate_atomic_write_limits(lim); + return blk_validate_zoned_limits(lim); } diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index f0f9314ab65c..42fbbaa52ccf 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); @@ -495,6 +519,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"); @@ -618,6 +647,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 75c1683fc320..b2fa42657f62 100644 --- a/block/blk.h +++ b/block/blk.h @@ -193,6 +193,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 ddff90766f9f..930debeba3f0 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -310,6 +310,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; @@ -1355,6 +1365,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)); @@ -1596,6 +1630,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 Mon Jun 10 10:43:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691856 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 A0D5F7E0E8; Mon, 10 Jun 2024 10:44:45 +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=1718016287; cv=fail; b=NrLDTB6nZodDC8aqz752X6MtwiMCt5I2pNwDGY5M0rJAubBH2wqCPpHYmx22VrM0DnJ4y8HU7joGCYHyF6sx+9Pjtaw9shN7xBoIwcKKHLMyCPcraxpprxW8iHvfV34fQCDHYYXnKai2fowB6ut7NAyUlZGPHaZN+y/8FTj53Xo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016287; c=relaxed/simple; bh=ncs+wF4cOU7J9wJvaw2fIEMsZ54T4tXBgS6yl9iSvOs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ZWPnK2lhIlYehcY4ucnf6POrb5lYjht0YnqGgkkSOCKlst8FBHEAwQMoAdBIVb4EOgVtvnriTGb9tOUy7Y1yp17Dp61OgM2aPCpC61yewKJryhKvccnovA7cPxM8bQMc3uA077rGiCPN+ok4Y3kmEUjyLV6tMOvAUZ5B5NdR8Uc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=HczBD6nu; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=RpIa3WlP; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="HczBD6nu"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="RpIa3WlP" 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 45A4BMUW025315; Mon, 10 Jun 2024 10:44:02 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=itKPfo0m3h5sNhivHrszfgjbCZt0T7xuLvyRk4Xw/Ig=; b= HczBD6nubj5keL49vJIqefc6bt0dZvLQ7VnVlk9kPyiFLF3Uj1NMZ40JiQFgzPu/ p/mHiIjNrv7h2Xgkf1oyqUcnZWKOEy2qhWrdAqtng/MxqvPw/CufwIloWKdLcJh2 x4uA3E5ACheFomx9smubGUSotC6dZfvfd+KyxFhurWDfwJJFYjhllmjM9PDhovEO q9wBdbzshV5uVtFbESPPjCkuLUBVa9oCf/ktpzG/K9ih24sGdzOZy0SsS/D7yRkY Wz4ZnceNS2Q/+Pz17HIEVvw8XM9X3g6c/UhC3oEPK7X/VGKz1yoYqegHFM3pYXim M2zTnJ+NZ372XigokC4nBw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1ma9wg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:02 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45A9uGuU036740; Mon, 10 Jun 2024 10:44:01 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncdukche-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GwDTEUZhg+Un8Ve/IC2H1AtjYLgEtF8pE0akC4+z35Q33eWNa3dK1ifoF/GA1PO31h31bmz9O57S096xmoG95cOPGAw8zO3/OmdI/RlcXgrLqEoCsOb82H4CczcaxbCqkTs8b6eu6oTduyufqaZkCg79bUlDu+066cu7Y/pIeMHXce8LtXK3LjJ9ddH+AuXvHzMJtAlxrfWaaRdWT0hT9AXGOJ993zpwcQ3Vhpre92iCPzI9n7Gw1Mo9eDfVGiIKIUYtrugPAE91e2xFYkKEEfOph3u4RjfwvMokIDua6es8wAwhGBA7IrfLe1qzoKaTqQ/nOxFb3ZN2ISiDjv+DZw== 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=itKPfo0m3h5sNhivHrszfgjbCZt0T7xuLvyRk4Xw/Ig=; b=FGT0GywegPaj5h3Er9MD7nsatQ074yf4jtqYIbC1Z13/gt/CD6E6RmTfnh6QUt8FaObAeBSzhLw1vkR4937ZLNraqz28b27ogss4bJ9jBmghw4lAmTC3eJWl+DZKD5xKAivMtilJDeFRXQfVlC0xqFrIHyxncnKdMAXtgPo1QK5/R0oKXvK/ZbkHCQ4n6zJYtbiH3SCAXkd1lo8P58pCbvj9VV1URaydOratwUdjYuOCNH3luaS7b84V+sJMPYS9gI2t6FkZz8qIIJQmf91WBvlW4jzM1Sz++ued9b8jVX5Y0gE0B2gh4g++GyW7JZpcJsSI3Lfr8A0mnrQLgEKbcQ== 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=itKPfo0m3h5sNhivHrszfgjbCZt0T7xuLvyRk4Xw/Ig=; b=RpIa3WlPNTys31HhPz3ADrhcLMPQjTZ2r7DlpzKbFlZTx0ux+xEWUAbm4qVTwr9V5bsuXC2dCXWDXjKDJbEiB9r1Ir+NLyrolm9zOGbZQTXQOZa5YITYLY7kh2YADKYv7ulZ+n+3Q8nquCv7DPZfWrvkjLLT7MoZjMs4hXDlCKI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:43:59 +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.7633.036; Mon, 10 Jun 2024 10:43:59 +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 v8 06/10] block: Add atomic write support for statx Date: Mon, 10 Jun 2024 10:43:25 +0000 Message-Id: <20240610104329.3555488-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL0PR01CA0024.prod.exchangelabs.com (2603:10b6:208:71::37) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: 5de4687d-f00b-4ac7-b449-08dc893a3c45 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: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LKFP3w61+4fYz8IVuJp7zjSEx/mr2XOxWeNXzi8B+ZQyDgfUptvl3KL/QGERBZteI013DNCeS8sEAcU3gW0nFGMxZBf3EUcdz6aYAzCNQYsiFkEXCZWYEBtpPrbJI/saWE9lmoWLkvCsyReHSEWs4dhdPOQjsLl26ggxiCNGBePaWdkCtFT5Lx00GPXhFv7+p/sdJ/mJVj9uXtOFALYZsFtfmDxy9t0oTccb6Brs9xHtqBfSg4ejETnxkjmZQS+Pvu46vT87h9/0OEDng/GdsB8DDva/aOU4xMOx7jH1Vzc2zDxhDnvKWpkusSWpRkbrr1QhbZRXCTpLiHxrn4HpAWknoz0+4JmV/2FwzVh3O00WBycMAHBEIm+Rg91dfbRFmIHs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8vkcE24hvLaArBAjaK69HV/9EYJepIAiuyhtF7VUSWEooaH+LGfxLMJpW3DIfIBMO0T/iDZIM0gG4XZcrwZoH2eP423NjQj34+eou7gTcHca0C01JCKoGRqYh2GVuq3Kocy3+xpMMeHPwkUtL0b+gLjXBxBkemUfoLuFMrMN+kEoBedLail1loerXtR5FpAWpE1uQ7orbVjxSFuqbfrSpymawn58WVWirbXFPRdarbeMKTMo6PFyFUqiLMUT/xadRZ9+aSYsJ/4rHb3d3BjAvj2CBA0p9pkOuF6Aek/usONmFMRCeVu0AEZFSpRe5248HwZxp5juJcpzsHje5Sv3+edgxdvZMZl9kq4DKC7iUH57TZ2aTS9rVfarR3odRVM6YwJ/V2BUo0T6qJoscF11i2WRAUHClXNqRURHfLmKuN0QB9peYrwFwWqjhi9wrBXHiGBpOWv7HdjsC1fgqwhUSyqkmh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8I25wpu3Kwu4v/6/2fmhPMtSij/a5Zdnd8tHnoI7b8PLjMlqUHvvrWvWaemympQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: CFxSewXCecsCtIZ4uxfNMtZJMuQIJJE9YlJeN3C1uooEtCkb66w0lN30TTm1HYH7fqPPDVkOYobSXD+iuRIXITRyrfvYPxPZ831RNjtezU3ZCXEJXyX3zKo+Ou1GBh3LwB2l+n1tr1kv8Sx8ffyGhNFgyFhXzTASsvfb10hNc29ZLnSRrobMEocqfrbRZ3EjHCIMnOpm8KaRmUqxNY2nq4dlIBgmL/2d53BNvpO4RV8W8JK9a2+gsjQi9nYzsqXDDePnqo279sOo7Zdz0yDhrJrR+Ov/OERZ6ZmpL7sHFdhx2m7DpI6FNNr6uvXfswlstNupjnBpjuKfLD7DwwSlxxyl9rqUPCmjSxUvqkAjrQxy2SgjFHMuAzRYDkv2/Q2TxIiQEoTGSpVRicG84tB9cSIDDIIPcvmCn9GQaPo6E66NeIC08roOKMGJ58WRDUCb6BwuIzDw2cnhgNzogTtneJDTNz0V8wee43FozK6RdMb3MrQKx1R7WeCAJvuYT02DlNMT7nkepqkW+3n8Aj7cwl2DN5WGKuYxL8KG8bw+J6BdTNdsNImrJ/P0cb9SOJuu2BmcSU2lp57G85iFp9l6vtzYjvoUO9dhBwTTJ50ryho= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5de4687d-f00b-4ac7-b449-08dc893a3c45 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:43:59.3232 (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: w4RarPeDOYFEhjNqSgJBMrWI0gn2OrdubQEnFNOjbRRdC3jxjTxeuMvUVg2WtFwvKI+O/j3nmtrWvQvcaXJ89w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-ORIG-GUID: iYeyVErxFtTHqCiL1FNJXu6v5waaQxz2 X-Proofpoint-GUID: iYeyVErxFtTHqCiL1FNJXu6v5waaQxz2 From: Prasad Singamsetty Extend statx system call to return additional info for atomic write support support if the specified file is a block device. Signed-off-by: Prasad Singamsetty Signed-off-by: John Garry --- 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 930debeba3f0..d861715c0f4e 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1590,7 +1590,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 @@ -1608,7 +1609,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 Mon Jun 10 10:43:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691860 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 9000D139D15; Mon, 10 Jun 2024 10:44:53 +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=1718016295; cv=fail; b=DFrl9w7Q6U61qHdjK7+yC1puzIPxfhnZhd2Ut4ncGQe6xp7oZTEVENkXZHXVk/ch1gU81uIrqmK9nPg4x7z4mZW8CPx52pe7h9nQNk9AxYhMdO7LIBm8GdPVPqH1yl9EvsrlxmmIUaKpU9sfUa3McFPRwv6ZJ2bhdsN3FvrAud4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016295; c=relaxed/simple; bh=ai6/2WKplFK84CqxX4DkGF2xmv65PJnrZBzS+UzOIvA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=PzVZxfmA5Fcdx3PKzIRAOGjQSeYL2GPo68b1FPmLA/S5RIbkBO9uOlZqTIyYlXxZ6gk5qCmR2pi+y3PYVT66imExhpB2AvxWCAW4a+zdDlbaFHWZFPZ9H/h9USeOtlssjMo+Q3Wiqh75Gvd827W5on8+MRZACFkKRxmZgrxerJg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=mUNPKu+P; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=JditkVOh; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="mUNPKu+P"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="JditkVOh" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45A4BRx2024983; Mon, 10 Jun 2024 10:44:05 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=taJdAFElvtfquWhoXAxM8upTqJSXW9dQcY/NpA3sNPo=; b= mUNPKu+PfU5DA6qdm09qhstK+nnosBp+5i+0wqQcuI5ynaP1J1EYcO9nqjRFQVco u876T663o7Y+ZTNdsrx+araX5ZC60sAss2g4lNIX/cZfDVPaSPuh8hPGo79mQdat ZArwvU5SgA+D/EvzLQPGcbihB8tyMEFwL4yJH/3+386oMO7Ml2OGPrO1qrCCUHLD TzlqLrXJ2TEv42F6Omk6CkOzxOUYCymXhDM/IJpotA8ZtVI3uIj8Co4dnC5kjZGE T7VUpbkKhLZ4m1g+mTpV+pqPBbDs9hSLCp0wlgifSiDcYV/cRlvY4rmrkFTGAopm mmEfbh6ww5T07VKu7ScQLA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh7dj8hr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:04 +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 45AA1plQ020108; Mon, 10 Jun 2024 10:44:03 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ync8vk8yp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H3piYBFWc/0Www04v1Z9m3b9wmDXRoLBp9yMgmqiiSXC4BzvtiVEv0Dmv/IdKkBdvnoDq+q+W/UcUPxAqOPGjlPAyLTrJ38W20rAVnjpgqE40x/Cr1tWUWBymhr7iGHdp0xO/6RySerF3+DMen5Fte14INuQmFsaYAbbH7fjOO4GioQNCys9mYQleykj/4W0LJbl+blfUKBzX40DrS9QNxjSdKamrAVY6+1doh+CRXYlu/ZIEk8ux0gilVQeM0YNMOy/tIarrhtNyYwX4PyyX9OHpjGVgMRtJX0mGreuWSfh/tPLXZp6H+GhHBIbBHM75bILAkpKsRmvIL6mlja9cQ== 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=taJdAFElvtfquWhoXAxM8upTqJSXW9dQcY/NpA3sNPo=; b=nnefrY9+Dh8CxT8yx1KpHRa/gCA3vq3l6VQHg9m/J/cVOGs1fSktr0aTrPYzxr4nsnEqQAhUA16iWD/BxPZBca4pmB3n6xbY6DWjC/Z1Af9uBSnMjM3OgknS++jbPfOcPgqxY+G/Mk65yGDKm7Cad8QgKFByNILPNolpU/mexLFUG2pa+i9hXyWmV8SBZZAmX5xabLx+lLT6ep8Q8mNv1IjsathrZXo5kHeuMp+IJZxA0GFa9xeBulJPaRVJDYqu5SEGBy8NZjQUnvA/wuqX01fDQPPv/qpYbGe/uDL9K1CDLYrs6iF3Kq+jd25GOM+UW58PdQUBAy1/94crDhDUUA== 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=taJdAFElvtfquWhoXAxM8upTqJSXW9dQcY/NpA3sNPo=; b=JditkVOhjgRjN+3FyRf1H8mc4++FA+jKMXRpPlCjkBmsEpQ8oyuqZNKJ32K3vb8YpcnDt2zI57GgIPRoR8CKXPyCWcMuA0TD+VDc1HUQMI+ysvI0AhHipNa7etUtP6DCrs9HqvXddkOABsU1+JGxCH9SbZ4x0k5GqJWgZRB0CoA= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:44:01 +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.7633.036; Mon, 10 Jun 2024 10:44:01 +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 v8 07/10] block: Add fops atomic write support Date: Mon, 10 Jun 2024 10:43:26 +0000 Message-Id: <20240610104329.3555488-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0244.namprd13.prod.outlook.com (2603:10b6:208:2ba::9) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d4a17a0-b4fb-4d79-c65f-08dc893a3d53 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: xCI9jKNli9U17CDMflwlV39GlYL3JD9a0WWfs4+VHCGDBYl97g0Cjf/i9ioaDsFcOwacaFk7KNGeouOkp/6DLnWgEb6KEOod6+efoo0CiROZBIXEBloiOP8WZ/7M6E2k0VMPZkVPu/v5ElgwhFKe+pOjKAMBIDL09yKXRIG3j8xz8Ld1m2Sv8NmRBhUzxYMCiU+fa5ejPLSKo5/iXYLZwq8bcxRX6CPPWS9PyFj6BVjIRdBfSFSE+Hnti+DW8r3+dfoaLeyOfWA0+/9VD7eO/ZNJ/UrxBN35BORK7dx7yl0l9KfNEbFt6tUIBmsjVZFIvBS9JuDKLON92ZCFyARHfRkJYx9ZBVPKLA+EzxcYqQAG/apBHHpPSu6S3m1FgqNYeHan4AmZ93K5RXMD+MXN+Iy+nHvz7yGK+a59ymcawj/LnO46rK2AhxVCzHYyn7O7AQT7EGMKnrs2WumD3tjVF2qVEvrVqjQz8mkHiESwaYfIUaSBzCOsCqafRk0dyENJXi0Spcr0MZMhpaliC1Oy+9awpNY5r6/wKMuGW014poFCTj2Ehm9heB4fOjZKqJsTnd5tF41cFxJX4+5E6FDjSWfV84n3bXdFEF4+NGzCD9hs9VCceXLolBYJHllCkkjPCimFZTo/5JRIDbKl4Jdl8VT3Rn/MA2OEDEfBROdh6HRsKFNAPpglBXPHedx9gE4H9Wb94n5wayJ/3/zlGuni+KZSkXdjRMb3xHF96pd5uaPC2oUsrorJW4aTn/03LGDBoQexxkrylLxDn+EHNVQsUFd/HBDLQIV1hxoSMGAsX56fHb1gET6ztBQImQF2P1/xM2uuxyo5JX29bR+u9GsbJMDpBWycs8pbkah5Ut2F6iUrFPZDZmxLNFzMQnNkVZv8h38jAYeT0ElXqrqdUWT7B7mN7xLvvjIcvCCJEajgeYmiRNC+G1dm0TYOokLwYtxFSxAy8PpB8j31UgZGFtit18+T8aIG5yR6XMereXO2I08x4pVmkNrbPX4jslQNWb6cQAzcHZCaQV8W6mdCPz1J1ENicnsBfz5jalU4cL+7NZQ1WbrEUSTBgsTUEpATBe7pSti21tkxU0LkiS6f+vvSPPwirnpE5YOyshih/LxqzJWIM6pNiSDe1tkje9YZ1x1sx1a5SlFhh5MDk/0MvTqWRHfWs+gk56pUGbItpjTGv4uzgPExpNNaDeNTd/0RasZn2GTuxv0DDmlN4atzbKRVGeqmmPhNDOIt4fiS952cF+29paxpIKcOmij0EkXS0Um5BfrY7I5KMvMFG3xpskvwiE3uOW3R/KjT0RU9mW7hxYzZZ8JllQmpbh4TuwJRsfegdCkzbXlvDMCzLKT+U1HhuUeApUr+39Dr6WpKhW5N2HA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tSDJrwjxJIK198lrQWsivXhpsy7/ap2DJCjQ/R0rbR55x0k2sdhyFVuEFKyQv04KJZ2rMGA/w0oT1OdfDWNXbMJRzTVtP63PIgO4Xktvrr+J9hNhTOE3cO7+cUXsZ5ZU/Soc4vB10ek/7eiW0Irk8Q9fbaTz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hA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d4a17a0-b4fb-4d79-c65f-08dc893a3d53 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:44:01.0844 (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: Mffuc21RzOF/Nh1ZWw8Xk+IIsw+cwxO6lwuww+oRnI06KW81IvIlQi0cqGU+PPovwOR5sB6fzrIb0E1A6pfaFQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-GUID: s2pGwygE7nT4orZVtJQCZ2E4fi9B_y7m X-Proofpoint-ORIG-GUID: s2pGwygE7nT4orZVtJQCZ2E4fi9B_y7m 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. Signed-off-by: John Garry --- 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 Mon Jun 10 10:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691862 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 365C213DDAE; Mon, 10 Jun 2024 10:44:54 +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=1718016297; cv=fail; b=cOmsPXMi9q4vMbhcmDkR/F/Hgqx1bjT6sJrzLEKMR0eCHUcvOQOZOunh9D0kjpZaYPnXulL48rpIx3Nnv9o9saMBbn79SZtzxCnjxDjHeZYBCqRWba5IbVZsQxaV0z7WaBElk20L8l0nfSttXwtC3Y3KcB4Jsq93Zw65GBfK5Rk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016297; c=relaxed/simple; bh=fpBs8Q05QP9h8997Tapg+W+QlIARQJ0aVgGpHmiprEA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=LmDmeSRR0EmdrrCK+2iK2DBd5doD1eMOaJ5cZnPkJO9jadll9RENCg6VGkbbWOaLN7/GMLYMmrXNvqggPZxBcIlCGm2NQqAQ/6qvxR9FgTr5d043PITQnObv0ZRGlbCNrBayn6VRDdUF4xpkaVe1ofcxPYBBuu/QpMGHsg6y7AM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=J4oxjBcP; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=nHo/EqA3; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="J4oxjBcP"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="nHo/EqA3" 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 45A4BSKo006761; Mon, 10 Jun 2024 10:44:12 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=tZ9etgNWFzxoGl6vttrRSkXH0odkInGHkvSdo8PtLNI=; b= J4oxjBcPfwPtbC2espJQIa+WZM3q6TI/vIC1K/wkSW9i9m/KbbAtJqSjYMyD6RcE tMiUartwJRBHcOu/TJZZpXKABs0HK8SAwLoIGknt6LG5zPzJtbrJT6Pf6TVNW+bL uXlS+G977TK5C2Nn1nqD+S6oN+AHvVO4SlAa5W+dkARSeeorgtjgRHVX4DzVv6ai vHj20NLobM11dwRUiLzAL6SJLPLK5iWH2czIxEePxWfzo1eMr+cH2bAE40cIeLSg Ohf1wJTaMVPhTUKrvI68gLeT+RnVGgr7gs6ZQCLKsW1urdIgGFe7zhnDNK3vRGHH PbNCD98eH1hR13GXHT82Pg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymhf1a8tf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:12 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45A92EWJ012416; Mon, 10 Jun 2024 10:44:11 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2040.outbound.protection.outlook.com [104.47.73.40]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ync9v4sgn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rx+doPyj3k/MX0yUsgKPbAu16zdZrXqWvnAyDbA8zLkxVKdYshEornCKu00OWsZSOcOeAf0413PsW04c52tTM+x6yhqaXQ1VDOaVVUA9fwHhZoCafE5OVZhTRuZh4RfEQH8uxujmvGqYqBwyluensDANvHPmhChBSV8MBFEY9wyixOWc3aOeQgeOdamV3LcyDh1mCz8u/8FKui/clvMDCJeoNX4gvCEHmY3SgBWIvkmpp8uxxQtzMI1g6rgxpwhzjgoh1eXioGQDruxsz8CFVzuC+2IALtBM2+Ehr7cUbfT9zTJGWmhvqKx1FF7dG5abi2IKi8+jQtBRjRDro0vjdg== 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=tZ9etgNWFzxoGl6vttrRSkXH0odkInGHkvSdo8PtLNI=; b=VixMAchr6lyOmNiYWzRl/WpdgFUlHxqVXfdhT8sCGP14gWkOkvMcXv2Yfmpa+wgIX3RO/8OMF16XZfHIKq4pim82hXWbabvL/ldcTdOyGcbEh5GjXPgIkiiHVXZJZTHvwCyPS7hmd858/Bz8aKj9hRC/lzu+uCuxBff4t3IPYvUyXKsGvoisDBBAjUec7cFxPhE/o//Gkz2eEZebbqWvCJ5T37HRb6uI5REYu0hOxSzdPn3Yn1hi+q3ZJD3jev3TkMjmjzPj5xN9giZvgB2zkBd8eneMGqAlRnP3UMdJR7TWqzHmtNAsMsdaao9gadKzXQJs/IU4N5YLxE3aj6WR0g== 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=tZ9etgNWFzxoGl6vttrRSkXH0odkInGHkvSdo8PtLNI=; b=nHo/EqA32LhlwMyF7m6iQGBzpf85K4Wnzg3eaGr0mjDIPRiCbTgrD6rYe/Mf1F9L4Hc2c+7q/BbNx6+Pe8T+PjSYCEN0s3VNGV+hIeSs6sZzpgWZTZ6DNDv6Kn35yW5OmoD2zQPUyRiw6s838Xvv+4VRfZUW3nTzxSmYo3SqzKE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:44:03 +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.7633.036; Mon, 10 Jun 2024 10:44:03 +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 v8 08/10] scsi: sd: Atomic write support Date: Mon, 10 Jun 2024 10:43:27 +0000 Message-Id: <20240610104329.3555488-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0257.namprd13.prod.outlook.com (2603:10b6:208:2ba::22) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: c3113d48-65c7-4776-6f0c-08dc893a3e6a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: T18ynjVKtInzXnzUIzsjg0D8y/4JtjKa2K/L+jJMWXI3CAarrB0STeJl4CHfAxkH47lI/XwORaHA1kHPjxRDBX6bAgjK5MkE8hdFL5adOgQl1zIwzl4aSZWCNIgUo54fsEA1nRB2KQ5hs27Muh1zpm6hWENh9Wqnod+8JOg3LWzjb5n2aoO5ieL9I5RWc44frcfnEHsDL9EPC5j88hkQfQjBSu17F27orofZojSfia9qL0UAXuMbCa3R3q267zxPL0KK6G/uPFq14tarV/Btw1hKgWCf3Nj2Le9Ezgr3r1q2++wzrRzg+nrN6RSFkSJXvgyo7pqhHfLvlUkXOx0zeSmgpEwgqPa0VOwuwhjo0BcY27H1oVDAKvPlZq04uw3zcUItEQZIjGxvCeF9GOYpln58E9uypEFTawqYtHK6BsmWJt8QWaDCuvM+z4a1UmLua6wlYMtK8X6SB6p9jBfdQPf276ujWv+D5Qf2jQ8vCIeWGmaIg8SEj/88CnUd66kiwgAWq0DiUR2XVGIZRf4d8vVoBo/XJik0MnxvaxbLaPXAUVAfBAgIrO+E9lmA0g5+//SB8Yt8VUfLxnR3WJrfB0D7rwkyooPE+pXLbqhPOcJxoSs2bdBSG4cDesCimKuycKQuBQrJ2nar6unrfC6PQ7EEVsbDLOEzRBmZfpQQtkLFqFMqajiTzBwVsyUeDfurWi7glqpMx+l6bLgM7EOhm7mRGc8R8HDms46rjAlncsF3bVqpR9fu4AoPLe8aKAHrPRCZKGOZuvfPnyrqehju4ZqsPgOC5NCYPLMCq5Zi0GIeMfQ1iMHAM4B1QaBmYsNzPv/YCs8Egm+OMr+OPWeAMmxqu4DoS4/jKsykhI4h3kdXEIKQfW6gyBKsc/CVHPcScnfkWsAadQUmw/qdd4D24MrCBt0Wrv0otxwiZF48X95BOabkEKdx9tZNV5VPuS8Tvj4+tX2nkI2RVcbowuR0+xmWNgec49fcsyitbSFshyQIfYAC7LLny+CQrWQ1G/rGI0O28AH27K6PjvTFGcWknfnC2/9uDpA3xsjNxt0VXc4iZdkSNct37L/VqtXRj3AxGuO/FePTXa2aOCxaZPDvtS4ETICWAtF0/rOBCRzMLhh+MVPziazvSVxcYSWjJxCThXEYZ7bOEbcHHA80aR5FUu8FtD+6Tpg+YCN6WAAnH+4//hvOJN0zYMC/tFy9XQbMeuOqyP1nw87J30tyePD/aDw3p7xdXyjmouZ4nPz4W8bSQkouxILirWMTz0M146DUMI8X9YR52QgZzbzzBz6myyHqWB6LezRabPCnzWbVRIQ7hxFmNa9TBk9AJEwEC+yyproKGxg7oZ1jTWlOVsIxl4PrbLPZkoYHybot57zT4Jk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QHxWxJFhY0QLoMDWXNiLbXLqyXpuNt6xHAXRJA8SjteoLI00nVloJYHo/DYm+Gz6NjM0LuiFTcf1Qj9MbUFDSpcxaOerIo/VIhr/Fb2ZBodXllIZDJffYX5yJsVRXMW/iBtvG5HI6wQu6YA/2DguDPE2l/9qykKxiMI6BsrQjoH3+QYrvpTkXNpuHwqW8XUQr3edeZhut7CZb5VlLkvcPVNgqOh2iLm5tG1WKtPRLDJ4RL2FHeD7jN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apmgdFiLtV/o2ORVou9zxwiMKzCu8SaighviKcwYWozlcD1a9pL122vO1t7seffPKXVXdy21DpowmYR2UlzdrR6dUyhqqqqzL7ffD9YR/uf/T1otY/ZreSYYDoAKadg5Ae/1qKSl3oWI4Q4g8xI0m80aqSUQ0am6uIuPAGKHZTctLsYhiAXEFySUwYqFAW/TWLIiZVBSYBv8Gd2l+jVJVNkJaCGC2EMnhWXz2hWTybKd80Fl1J5qWLKsx9/U1Dn3piMXRrP/e+A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: DqO7M0rHyZy8AOdc11lyCek+fg0T6QQBzM6hWMZTkRPKMNciLZE7Qz4we7I82s+qejdjKKp/bwJHuyODl4I455Nszm1QDnqblfFVBbRb491iMMtEcBrfJpZ4XPALfUCdCWSGYBybdYUJMySYBPmhK56FslgCR2GweYP/+i3dJQDFjvqEQN05eqMrhjKfWFrwH+oHna271AKjsSKxUNXlESKBsp6yXggPJWfxGI0AchPD7dfjWqSzOV/WSfzoyxbGJp8vg/MfiwYC1a4Xxe87F0w5EtbilSFBWyWtXRXOnarFG9uP0DWzecQlTQ2TEqiwRXH6O9JI/JgBGo/f4E5IhH+w8nYiC1zcdSZIjgap3FarovCFAhPUYhoMYRS/pu99XEzysz1cZ/WJ2iWc2wptgTPx0H5OvSbnhNKGYbacpVcB+J3xxhbussK3RDJYSLJkOZoMqYttGZRL5RK6mpqWxgIZ322uo0qyhzChHBhlnULQ+1lRT8z44DMDtp2p0Vx+fZ9hU1wA1NTGCPVoR1avjMtNBsKlkKhcEXo/mZeHu6HASxkDU6huV9ze1HhGpVVAKYfSQPl5Jx5I4bwwNJ7Aeb8RYEvE+4/COqYaKDukvm8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3113d48-65c7-4776-6f0c-08dc893a3e6a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:44:02.9644 (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: p5FqkffnvJoXcX1ApUlAv8e6PUomKW+RI27xqM0i86yZmb5x+TTFZbHKHkHRqDRqeVTdDhbqnQGC5DS0Tfubkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-ORIG-GUID: rAFomhhpeKREl9-oWeGfVwDAPOzRsmfr X-Proofpoint-GUID: rAFomhhpeKREl9-oWeGfVwDAPOzRsmfr 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. Signed-off-by: John Garry --- 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 d957e29b17a9..a79da08d3cce 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -933,6 +933,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) { @@ -1231,6 +1289,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); @@ -1296,6 +1374,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); @@ -3256,7 +3338,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]); @@ -3271,6 +3353,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 b4170b17bad4..c7ee1e9c2ba4 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 Mon Jun 10 10:43:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691864 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 A48EA14D6E7; Mon, 10 Jun 2024 10:46:12 +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=1718016376; cv=fail; b=sZmgWJbEZgthjnU64uye8L50jJXLYSVYxrIfY2ZqYhHI02bkKcPSeya0Exl5Z+ettMEd9Px3l6jnKpE9ECklklh5ZNxQucddEX8T+AA60KGX3TKT/FEz2xlQ82kjGie8vkidlEKPgBFCb0pzRZAjbbIUE5Cd5lOtMozBVlYE69Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016376; c=relaxed/simple; bh=R36bax9aDLUanI5xVDnThFLhPtFRZWJmr5/8ECTae8w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=qCEpP2IWaMSwyTPi0s6K7AZF6pnonuXHvOaobcMaRmgRrx1dyz6c4IPGrj0kZmbQcI/pr486Xp9k6Fgh/YYXCTsgPFUGmvpkMRSBetyQ0MV+wP3clVpJB+lWPuPkmaqx1L7Oc4QaJtMV6352l+MbyoBWxKm0MgZ7ex98Xl9n718= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=KxlMigWS; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=MdBPCLPU; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="KxlMigWS"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="MdBPCLPU" 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 45A4BO3N016241; Mon, 10 Jun 2024 10:44:15 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=p9eg8fdWXMhNGFlIiazULYvvLmp/RlUKAMPSz6Wp/aY=; b= KxlMigWSgFigawB9VkT6dkNGAeMWwyFf4Rd+oMJAmzNBSWLHfUmVHgI7Z7BESv/X jH/q6K9gOkOmU8uDf4asH2m278MYB0v4EyExt705lXH2lQWFerp+sV4S9XqSH5YX JSeiA2msREsLvXlUnD6TOjwmg5Yuwt6o/rRqAcfptiF0mG6wK0lwIv1AwntODE5/ 0KKKUtNtBeCJlcN8ZlU7APNfIxj/bfsy0hnUw5wTq6A57PM8pTz44USnMT954M0t H7qytc+TwsefgiQ2MgkbaS+IuZubqKd+cQ4GFP497BKkotpllRa0NRsHEnctxVRz NYGo9gRo0RD3MaRvy4Kd4w== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymhaj28ju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:15 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45AA4BwN021545; Mon, 10 Jun 2024 10:44:13 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncasuep3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G4oEQDZtQpdKhkM7gWUg5GgIadpE4T/RLiSNDLRaF2v1qlSBAYgjGKJhPJr19dIFt080Cvl9iVLtrlkaN27N5Tp8R9bu0vLant50QFEqYvCfPszcDyK3ZsFSPatFC73B+XattBJwPY3mdfxF8b8DU4ovA1PICbC6GqK5vyk96gwHytFlijAq7UmWGS57hzlCF5gxibhtgxmJUszqxTd8btCB8h8l+tFunokLsvR88nEMnpN9k2gki2tyGy5XkOXgppzIOmRfePicBXuD7uF6WriPwX7UyF8dkSmwJ/6DEWGt9WKYn0ITglCimEKlWgFbcoMqZ6ta+aMDt8LwUENsEQ== 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=p9eg8fdWXMhNGFlIiazULYvvLmp/RlUKAMPSz6Wp/aY=; b=Mbl5GAUpZeCWEngv1gW8+nw+IC0upL0v5wFP/T9J1uUpsvfha1qDB08HGsIVCNQ8NusXAYqMIcCQ9yh94fSVsfDWTNQUYs3ivLeUcERwYpO+iLgyD70xE+U4oZF9adFUq007V2kLd0VTXH+Ce2XiygrSXWhFOui33Ddajra7DbwzjPwkDgC3RSvnzbiI88mFSariOCMcKNIUq2GdIwWVy8M83QZ6FfJvMt4MRpztXtprku5SEL3VqDz9Pi+AzF39iRPd3cdyzb/DqF6uU8K7OHFrXO9yDX+60XBIkmHWpKOoZa5UInk3ltFnEtf5O1bPCYmvBleDG54FSlsV48JzxQ== 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=p9eg8fdWXMhNGFlIiazULYvvLmp/RlUKAMPSz6Wp/aY=; b=MdBPCLPUheuhrMaYZysHigANtWMYFc9aHUiSQWrmNfxJsSoYMMJL5t6Mo73VMivqA197bn5estXTqcqcWpe0IpK5FlXXPZAbzMscxC4tM7DeXihS5XmdR9HFDG2xVTEKnl+VhePN1JYLVoQvIGxKNE0/ZWHPy+X/Yy3MpEnv81c= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:44:06 +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.7633.036; Mon, 10 Jun 2024 10:44:06 +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 v8 09/10] scsi: scsi_debug: Atomic write support Date: Mon, 10 Jun 2024 10:43:28 +0000 Message-Id: <20240610104329.3555488-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P265CA0298.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:391::8) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: c3e394c7-0295-421a-7e19-08dc893a40ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: NPJwV4v6I4OJnbITnCBtkOma2xng2uupRHIW18PfWcCfxvI/zG6CXbrt4/Mw7ZMJoja0rMLYcToUnboGHXja2GnZbjdf5Xbb675bzXYLgXDEH8SPnGxUpE+KTnkE0fDeMJqWzrVdgQimWBJlizvPTdURgxsvu6YeixQMd7YW+Wd3VoZX3/COfDyGRXVFt2XRSdCKeLTSm/GvLrwIHp79y6Zep7PDCBVk6FRa6Y1v4LbDdESO/jwromp3j/BWgiiCg61+DAyutqkyJqJSabSPYdVOB2DDbA2ZT1VaQB0SBVI/53lA7t1UVqNoKiqe/l7V38QYkI2iv0ri/hCIzHC8kQEXyDgVAtMdwa9zwEpAQHQo8u38aNr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:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: P4whFXzOETjMdaQZZqIlpAhmMvRFy9AdzJ9GM3AMdJt6PhwxH6ZBS2zIcZMZmN4tsIVFR8l2521HWYP2o4ZjM+spEl/fG/XKThOr8CvYGbFcyvm0VQIvt2k/f1rE76HSyfSYvsOtaJdr46y0AyfttLo05UUsRVLVM7rXrewAIbD0JYepwOhDBRbGvy08z7An7/oN6oDjTpTPiV8Ya2ffjjuGqvJtHS9J+CdWFujjC1jHZLBAGvHdwPtwAyKalnVhNyfLVsvLGtRNCHjAv149/lNJVBeJONkzPgUzZG5RARGzMpZ2VT83cSPLbiadAvQcxDPmp6jcUWBi1W0c37s+vxs/GbrhSkGtuJicwPk2rTeNvTOUQU0AEIbo04Pgl1+S7AeRNdC3sHBEt7qed++/GZwzMl5+FxGL8BMxR5SKlTK5pSyiR5/qKf8Lhu3Wt9/IJ9beicF5+g6p0uiBVRKaBtIXSjg0YKrP0OvnzDBVMavv5C9Rv8JXdKDW3IkgmoiJ27fGAyTIhM8m9TtitGlQ8WMm4q3Xf+Hn0dSi0E34Mv2rnQcUsQpM9iGbs5OhGI+g98Qza6pfgfGqRLsICzzfGgIsfEM9om+FL3rbuf+d99IqGP53wmJo6F94+lvAMf6ONSB+iA7zvvinb68cD/IIHyDKOLpv+fHJGdLmDFYgLiC25UminVWaJqF3P6nXxIRjyGuRMk5MGxYY6HelyLOkAbM1+ewT+c/TRYv2XJCYqPvZCn+2HQycIUdoY8tFGOfHZMZkEA2RULiwS8z+5uuavBllnpU2bLy+UxGgZE9UKC+dPEn0p5FYsPcB2AcKM3qkP9dEzm61C2TAm1NOZGO677AW7WwUfLyZO0YS4EKKCUUkh/cca1GV3D3lIk9x4BpArQmzAxhMLg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5VGkyLuN358yTkbpnOyWzzYFqCkKNkAzpcbk9eTpZK6bU3Igsb1XQoo0w90DMhx9d7C4G25poloOifsxe+L9lwQg50lUUaRr5yboTDZf2U9xGivKjKD4YaoAIfT4PcbTPgqzljb0tI/e0VZfdw//XMkFj2trw9uJ5jNJtoRQYRrAof60Xy+RRsxdGG8hcG40PtLvuPmuNsbKLk09dI1RL890Pxftrqb52uqnj+3dPTCVcudH65Uh0+X9zz8ByRi7nwvkqU8UOXwHITKlk+ExvAzg2FRzb5TbeUet6GPmGywYtgqum5BWLbwWv5oQtbX0gX5Qf8J3nzwxvDLaROsuw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3e394c7-0295-421a-7e19-08dc893a40ad X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:44:06.8718 (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: uRPoyLI9X9lJJeTQaXJ6bT+1kYz8fQwiN2JfqnDLLtRjVXphNEb64KGEsD6L92XCylc43z9RQiVZyBzgbucFJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-GUID: TgZg7ofNf3nr_iPpGIZifD2lmcBYdhDA X-Proofpoint-ORIG-GUID: TgZg7ofNf3nr_iPpGIZifD2lmcBYdhDA 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). Signed-off-by: John Garry --- 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 Mon Jun 10 10:43:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13691859 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 1BE13139583; Mon, 10 Jun 2024 10:44:52 +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=1718016294; cv=fail; b=cwobYNeRyFCIqEMjSrWB7usSkSJijsZ5Pb2xf8fdO32cOL/2r6igLEnDyq/Hc3ny+ljhOmd9IAtb+9bjHsfjT2+0KryuUvBs6WwNBN6t1f6L3j5BVbYmw9t3kT0Qt1ouTMI9+1cNp5vviOm7MKjrdX++hpz4DKfdtLAQ8ccN+Sg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718016294; c=relaxed/simple; bh=iki/1NYZ9YoGpsiuRdEgpVnO8uPeskpeOIqE392MusA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=sMMDWB+3ygcYVenZrcIpqOiKjWvG8KUR3QzsNSNQ7rc7xvd9v3DLCL5elTjl+ShBwkDoVL0WcOpD51y/bWAcJLIjtbH9bZplEQaTOr4XxD7AZXB455LVqA/5D41K9fypyrbaVdJf6446VJUZVVM007ZyODdN//EXx+U02+fh0rM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=KjXCX7SU; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=azU+s3lS; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="KjXCX7SU"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="azU+s3lS" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45A4BRx6024983; Mon, 10 Jun 2024 10:44:16 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=IzYMElQdoafm/KOiCJoqkqo8DHg2mUS9JMz/MJ0HTqY=; b= KjXCX7SUri0Sl3DgGrzH5Y6jtNB87c2mdEXOBWob+HIJUVYxKMGp6ELzyiVCl1W/ btslEEuLhMZmreSn3Slz6d7T4rLkcWIQFUuB8UyetjMQCERmRbnl84L3018hIbOU s5FzyqejswV344MQ0r3G+NL0leWo+JE7WmA92d0AntjWRIrKoirFMyCr/BkHJ6q0 VupPq+Ks1oRlzcZKwg2qWS5HrNpSXLgvItcSbHwr2jktUYJAevPQw74ILvJ/W88J /fOZxmeUEROhUI1huL7VqqU+k3YOdDtVZgGISu6fBaLmmTkebDPM7omPygeU4l0I bsA8h7qC++yMLWlcqKEyNg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh7dj8j2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:16 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 45AA4BwO021545; Mon, 10 Jun 2024 10:44:14 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3yncasuep3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Jun 2024 10:44:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wtl/DwLov5dVcfFR7HI+E9HK+UepQoYsyZMK6k+/t0/u349WfU0IsgCGI9mCKaKbFNFMNgQJBpjC3tLSq+mbwncw1qPRPL6W16pE+98onf42jQ3ojxtQm9ejIezfj7IaAqea4JRZxUa7BMiDQ8ATLSuynDDw4IlK46muNFhSxohr0eiB+DLD/7Tqdh7f4KpvglBTAVJFW/FcLMYcu7q48Q09J69C5MweRaPOudzsIkQRHT8trNR4x5tlZZJzg32j4J5w1zaRZ63FPgUomREoN6Zz6VEmJGzkxUNbEVLbMJ/AWpaFg9+1jz6ujG/C/ISkZl6BxgcyQRoJ0qtsq3Zygg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IzYMElQdoafm/KOiCJoqkqo8DHg2mUS9JMz/MJ0HTqY=; b=W9DEgM4HoBgv33VT2ZQ4OJeVQJBFdMISM028jxgAl++5fPE7/v2/2BxKl8G3wEH91qzNB83l5G7QyWYIpNazkXu+8hFdY+un13R6hMbH/QLnzxK2yHRTED/NIKGKrHf50zzib5AB5pXCcDGvSc/tGWkEdLtL3bv9p4qPWzcA1JiXak7atHehc9kH9gyIhLUruxsGQjPN4/SA8cIlFOOYggr7X9AO2gRua+7gbveER5unt7ar+gNH2ENyEOAifmxD3Xb6qmcy2cVA8PcJ8+WdzR4nxDqZtddiU9OsO/qKD7qfVmGHR5upC6p+mmhaoU4gnYB+eu/AYOrwfPPLNfrfAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IzYMElQdoafm/KOiCJoqkqo8DHg2mUS9JMz/MJ0HTqY=; b=azU+s3lSx3xkoKCalq0N0SRq38SrbVfuYYTdH/IW9EgiigKdPYF8XyZfNNURfQ1B7EtwPdfBkOAv0nIAHVC1qVQluAV+vFORoZeQ+WBKpjoBpEy9Aiz2vAOZ4squCZA/8tKne7fMfzTGU6xFykFFl6ttSP4BL94vNUjsFc0P6sw= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Mon, 10 Jun 2024 10:44:11 +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.7633.036; Mon, 10 Jun 2024 10:44:11 +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 v8 10/10] nvme: Atomic write support Date: Mon, 10 Jun 2024 10:43:29 +0000 Message-Id: <20240610104329.3555488-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240610104329.3555488-1-john.g.garry@oracle.com> References: <20240610104329.3555488-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ae::12) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB5613:EE_ X-MS-Office365-Filtering-Correlation-Id: c3f4dc8f-58ea-4540-1aae-08dc893a4341 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007|921011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?yVpC5KDkBGUcHZUJPXyY/o9YAq5r9r4?= =?utf-8?q?dA550VptaiIPtFJZnn5P/tsrm+7f0C/NNthf2nsWJF+qaCDE5OSuSiyRo8avvdgw8?= =?utf-8?q?r4vDwm+JPbMu7JwatOOKRnwcA4K0/s9cNlyd/IsYUR2Tp992pP1yLxvlz60h+oYno?= =?utf-8?q?hgCd68n0u0dOCFzazT4eg6bZ0Ezi6A/Bua/vf13F1gFMEmVsgFozI1hYbMcexCs4U?= =?utf-8?q?caNq70Hrqw2QQU8N4zZ9BwD1aJH/mvwwtyEIf8SwJdu7RUOYFPHNYHWktAZHGDsP5?= =?utf-8?q?kCCubrnUllEj9hqSYWN2W+f1wJpxoVq485YMJptUBwhNAkeh/eRDyeFOBFoM5wlzN?= =?utf-8?q?buLYLJTL725bvIl7/zL/mD8S1bjHKKCfT/FBXt89iXqhVEmke265UTGhTv0XYkCu3?= =?utf-8?q?g/l19sC3kOWPDaa7CB8dGH6ybv0lCfMsDcnOGQMMHGvpPAs8Bq15b6Yy9ZHbpkQax?= =?utf-8?q?Sba1dXmtR0UeyOLoAFb6vcZKA0cJwsuIDVs+toDKJNI2qOcpsEbdTZZOIWoKSKzsN?= =?utf-8?q?Rae5RygVma8+/J35J8z4SGAOT3Y5rhXpRkKrJo/m+IaJqacQypYva+J4wIfayki98?= =?utf-8?q?E0yZsIYYRA01kWPNt5AqEbgeePTwPNqvCH7oHijgauTN02sdn+zKkjvL1LJh/RJLy?= =?utf-8?q?8bJ7nfhxUDTxZFXEHPAEUGS85TUaoJIsQbg4O4EykBXvGY9bVPKUijIkKLoNMnl64?= =?utf-8?q?89JAdLiPSqqxTtb3uIlkFDwZ37NHs8PTe32s60DDxQ029VvnHyG6a8ys6QFXMyONc?= =?utf-8?q?6ROj8ae6l4qthz8gBPuorSq4F/3sIgDb1fGe7/QlrG3jeoCULfZgn51lf20gRwg0d?= =?utf-8?q?88g0Xb9v/M3gBnO4lU2m9GzOOw/CEG+nR/qy0xUl1nSBzz/aIFIcqVGGN2AE30Ai7?= =?utf-8?q?v/sR0DoM/fCC5g2ZIccecu7x/PYOc06ud7b5u5aCIg3XIj+u36PXTDuGmarx/vTqk?= =?utf-8?q?otrJhQIzkBWR1/bmbCtQOuICaiDErNvxycaX0EJGTZ/rONcB6LXisBUi5j2HuXYWV?= =?utf-8?q?ptWvMbRC4N+uAkCjKJpuOp21mLG2e6Ne2EYz2pEx6NM9YCkGRLepgvez2EGVLKdOk?= =?utf-8?q?cEjFxy47J+/eCY1v8vwKNIgUdRfzjYna1czCwWseGWMQhsCa+weA7NM4WG1L2dzhA?= =?utf-8?q?AK4pzdREF6uyXwM3xfu3UiIa7RnZwXPYFHluEfHED0wheAjEQOUKdiDvDBInkvMHJ?= =?utf-8?q?FHD7RR/muvUtNg2Gr+LBtZrBO6RHBoUtIM1Acyksi+8kiVZ14b207C6mIO9SQ4Byg?= =?utf-8?q?w0ttzQBOHXtc2JGeP2S6dvPk0biwfYN8vK3U33dHvg80ETJJh2fXdtpA=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:(13230031)(7416005)(376005)(1800799015)(366007)(921011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?APV6D4KoJFuw3d9zkoLoQaeRTAh7?= =?utf-8?q?50o58ZyPnubLRKX8R8aAnVVMu6IMXOtkEkmoXfi633uB7LZSNmP36NXL1nHteC7Ye?= =?utf-8?q?Uhs2Lj8SHzKGxphw/As9s7ZyE0CLBMhuRb+Fd3Ug7Vi5tL39Na/+1DqDooqLSv+E2?= =?utf-8?q?GIVrqP/DT/uE0MyP7y6daGA7FPrjIDUoKrvX+Fp8oKoxaALclKzYPj+zl2nug5Nvv?= =?utf-8?q?JMVBmtfUx+z+JxizX4KeEogvz+GBnr4/7qduRzho8V5xI4A7z3t/GQjukvruScFie?= =?utf-8?q?OwjCXsVwfYgDEjKnvg6o+UQeiSa6R0euO7JvHaCFlN/sfb5kbBVhIMQJKtprJlbS1?= =?utf-8?q?Cce0IR8hbDDDIljxCyPBZFd/IMoYL+7ZBNL9QesJr/E+qvjehITsk70Hjx/evzZ7v?= =?utf-8?q?r5ze1jvTLr4U28hrAoGvRLLZ7B1lvHY5jvtWqXhesSbf4J0wU8kDw/IHe45OWGbIH?= =?utf-8?q?UZyqfzC9CLd2oejd3JYr6hHZ2q6SnYHbhXywOMn/h9B3lBMNuWEEkdASHJUmNGyUG?= =?utf-8?q?Ucw1wkKE9P0ykCdclCTRfXjAeGMHygtuma8n/Xg6tKp2ap01wLRT/6hx7Tcgy4sHA?= =?utf-8?q?HPTL4MlFYpre4remBXAXA8hElqQeCll9CBJlCR+nmZyXJkCsJQl5DLDbvONxn0j2J?= =?utf-8?q?z29xyTQDmT/aCB6f95M1HoHMqLdnQMFgmsMn0pHYqpwhYY1QJ8xwvbSyoGBCUyvOQ?= =?utf-8?q?w5HmS91qgfoY244q0nFVF6HEH8JiSwpVffD7QVwko4PurFxz0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KT66zYXtPBGpHMW4paXrl2ibaiugxnwrEvR6REUEdIKDfnDwEWTqYNXTDTyBTALMXk2r2fpcrsdT5b5fT3J/2SrM5X4kppn4rjOVSOhLYjfMuK4BdU9b/TibkQ3E0+/UwbMlv37SICXNS9N8jSMJst6/mdqODOeNQMqdsdvW28xhIUVC4vof2x8OMkQFRipRoHx9619WPs/FiyerawuITW8xU01Hoi0D/LUSN8B33e+l1VpLo4vshMFOYdh9vMvG+x2fNOeOfcldYSgEGtFeKMR0JSAIMKqKKCGmL69gSF8+D5Oi7PQq2s9Mi7Vwn+xS6aCMPjuavOv/gOhHxBUsVH6gxdFSJW76HYuZmaCiLvlgfqYcoXLdzOFOXgV8U74gRh2gw9VzU5IBvLaTOh9SsWVDo83h7DyV9xkjHG9VKW4sLIj8Arhs613LiHfgnbV26kMtftTntBbLEuCGDO482rcwGbKpXVVoN5Jjcdln3YJCptJ8f2G3+ShgL1GjjlcUbOrekrv7AmMs/+50z41n9wIYwwp3jcDW7O1zBwT+kFobWS/Kjjp3UMu1zsLm/lMxKaQEI7qIXBXAKECU6CIWIc/hEW5C9C2Qg7iYlY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3f4dc8f-58ea-4540-1aae-08dc893a4341 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:44:11.0211 (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: HyWTxtyrc6n7LDVLpJvs0gKax0gych5oGOvFGySS9EIoJbW2TqetlTxbV488HqVV9WpJ3Pyw9c5kT0eE1NtBqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5613 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-10_02,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406100081 X-Proofpoint-GUID: 3oVZGuYJx9fSa9lTTXE_tmRHvvyxknO- X-Proofpoint-ORIG-GUID: 3oVZGuYJx9fSa9lTTXE_tmRHvvyxknO- From: Alan Adamson Add support to set block layer request_queue atomic write limits. The limits will be derived from either the namespace or controller atomic parameters. NVMe atomic-related parameters are grouped into "normal" and "power-fail" (or PF) class of parameter. For atomic write support, only PF parameters are of interest. The "normal" parameters are concerned with racing reads and writes (which also applies to PF). See NVM Command Set Specification Revision 1.0d section 2.1.4 for reference. Whether to use per namespace or controller atomic parameters is decided by NSFEAT bit 1 - see Figure 97: Identify – Identify Namespace Data Structure, NVM Command Set. NVMe namespaces may define an atomic boundary, whereby no atomic guarantees are provided for a write which straddles this per-lba space boundary. The block layer merging policy is such that no merges may occur in which the resultant request would straddle such a boundary. Unlike SCSI, NVMe specifies no granularity or alignment rules, apart from atomic boundary rule. In addition, again unlike SCSI, there is no dedicated atomic write command - a write which adheres to the atomic size limit and boundary is implicitly atomic. If NSFEAT bit 1 is set, the following parameters are of interest: - NAWUPF (Namespace Atomic Write Unit Power Fail) - NABSPF (Namespace Atomic Boundary Size Power Fail) - NABO (Namespace Atomic Boundary Offset) and we set request_queue limits as follows: - atomic_write_unit_max = rounddown_pow_of_two(NAWUPF) - atomic_write_max_bytes = NAWUPF - atomic_write_boundary = NABSPF If in the unlikely scenario that NABO is non-zero, then atomic writes will not be supported at all as dealing with this adds extra complexity. This policy may change in future. In all cases, atomic_write_unit_min is set to the logical block size. If NSFEAT bit 1 is unset, the following parameter is of interest: - AWUPF (Atomic Write Unit Power Fail) and we set request_queue limits as follows: - atomic_write_unit_max = rounddown_pow_of_two(AWUPF) - atomic_write_max_bytes = AWUPF - atomic_write_boundary = 0 A new function, nvme_valid_atomic_write(), is also called from submission path to verify that a request has been submitted to the driver will actually be executed atomically. As mentioned, there is no dedicated NVMe atomic write command (which may error for a command which exceeds the controller atomic write limits). Note on NABSPF: There seems to be some vagueness in the spec as to whether NABSPF applies for NSFEAT bit 1 being unset. Figure 97 does not explicitly mention NABSPF and how it is affected by bit 1. However Figure 4 does tell to check Figure 97 for info about per-namespace parameters, which NABSPF is, so it is implied. However currently nvme_update_disk_info() does check namespace parameter NABO regardless of this bit. Signed-off-by: Alan Adamson Reviewed-by: Keith Busch jpg: total rewrite Signed-off-by: John Garry --- drivers/nvme/host/core.c | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index f5d150c62955..91001892f60b 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -927,6 +927,30 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns, return BLK_STS_OK; } +static bool nvme_valid_atomic_write(struct request *req) +{ + struct request_queue *q = req->q; + u32 boundary_bytes = queue_atomic_write_boundary_bytes(q); + + if (blk_rq_bytes(req) > queue_atomic_write_unit_max_bytes(q)) + return false; + + if (boundary_bytes) { + u64 mask = boundary_bytes - 1, imask = ~mask; + u64 start = blk_rq_pos(req) << SECTOR_SHIFT; + u64 end = start + blk_rq_bytes(req) - 1; + + /* If greater then must be crossing a boundary */ + if (blk_rq_bytes(req) > boundary_bytes) + return false; + + if ((start & imask) != (end & imask)) + return false; + } + + return true; +} + static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, struct request *req, struct nvme_command *cmnd, enum nvme_opcode op) @@ -941,6 +965,12 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, if (req->cmd_flags & REQ_RAHEAD) dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH; + /* + * Ensure that nothing has been sent which cannot be executed + * atomically. + */ + if (req->cmd_flags & REQ_ATOMIC && !nvme_valid_atomic_write(req)) + return BLK_STS_INVAL; cmnd->rw.opcode = op; cmnd->rw.flags = 0; @@ -1921,6 +1951,23 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl, } } + +static void nvme_update_atomic_write_disk_info(struct nvme_ns *ns, + struct nvme_id_ns *id, struct queue_limits *lim, + u32 bs, u32 atomic_bs) +{ + unsigned int boundary = 0; + + if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) { + if (le16_to_cpu(id->nabspf)) + boundary = (le16_to_cpu(id->nabspf) + 1) * bs; + } + lim->atomic_write_hw_max = atomic_bs; + lim->atomic_write_hw_boundary = boundary; + lim->atomic_write_hw_unit_min = bs; + lim->atomic_write_hw_unit_max = rounddown_pow_of_two(atomic_bs); +} + static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl) { return ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> SECTOR_SHIFT) + 1; @@ -1967,6 +2014,8 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; else atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; + + nvme_update_atomic_write_disk_info(ns, id, lim, bs, atomic_bs); } if (id->nsfeat & NVME_NS_FEAT_IO_OPT) {