From patchwork Mon Feb 26 17:36:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 777728 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 8800C605A1; Mon, 26 Feb 2024 17:37:26 +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=1708969048; cv=fail; b=tQ8sonoA4b+WhnpwncgyO8xJ112MVXSEOphYn7/nt+R7UOAPkqQk47O965kKRE812mc22sHyvMRd5HoqqUXes2boyyqI586AEALW4WLgiblKLIqpTsfpdDZp5UUGT+BFszU++/DSZSrBm1Q+ek7NLx55odQEVkAw5oHhXrOODEc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969048; c=relaxed/simple; bh=J7SZLmJmdKN0tMpMfOS+5xdLKuDvGLQyXizCexx4Js4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=aNhuM7sldnEO0mslo47LQs87xSyZP30bVL+D0uIfVri4iH/dBjjHjm4FaxIEWvvmROxlYKv3IIgRbmSn6JDQ4r+IkrZg+Qu3tEN4PDCzCWrwuLiX6eUEtdZQIbm9MEDiZ9FM+bRtkPDv1GStmNF4kk2xQQ1dmuqMG2DnNOM/vNE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=UZtnyt0Z; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=w7clI7gB; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="UZtnyt0Z"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="w7clI7gB" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnG8Q018456; Mon, 26 Feb 2024 17:36:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=esWc5rIYrO2nyco4iv76jP73u1y8V7yGOLl+U5JSHKE=; b=UZtnyt0ZsNlB6FLjObVcyfkgDjm2i3vedXRlmfXlbkViDSkv3MuMXAQ4Tslv3EZ/EviO WCONM40yJIKRtnuWWkEdexqcOrMjoF7OdK3Y7s3vAc6Kb8NOIpAbVSTFw8PBF0y8RLss lcfKm/zJhB+tZUdR9WU03lXHallZarTMCyAh20EPmNVTQ6Z9iSVJk7hiT8NidbjpCBp1 MRTczp4luepJh5STzS7Dm55MVgB+PyMrNZO7ZGg9ZXG7LlmuYcxeFHW7UfNV/oHf+4Wr KLXfUVCchih+b9358MV3PDXEeHa3/v5OFwmePpvT256PrlrCNDTSat1RBgp58ZZJazW/ Ew== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf8bb52eh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:43 +0000 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 41QHKcHQ009796; Mon, 26 Feb 2024 17:36:42 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w5w9vd-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QSceUVbjtvPuudEu5wMVC11+A3kk9VMi7FT8PsHTnC0+uUnjzjOFLUrJO6r/x+UGV4h3bBGq8LiK/0OO/pjWAWciUtCIRvTxMBVhJGETT7ypmxYMBz+6ZhXBxyLq/yfnV9TL1dLPXKKiLSinFarWVGLLEVVlxgbBMPc9uLBJOoDIP9NmNXBf7e1Z0fqAmSi6TdOABmftC2SmfBBBWCOMxCqiox57M9RosDoKm+7uMC+r6ulxFdjFqTUiI866r5RLiMi9z5rYwNwe4cGGDmuP5lXE/prD/QBP5c0dKBYU/H8L37xjC9aLsZM4BrTtsb7Lc4ultiFfyzoaXv7TX7IabQ== 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=esWc5rIYrO2nyco4iv76jP73u1y8V7yGOLl+U5JSHKE=; b=lbEnh1prXDjYxBtZz+C+42M9qRIyaVMn77SQfYXtVAESatU21AvUhpDWyneamUpbz3FGtAhyEkmFI9sMk7uo+OIbIN3smCSYKnOVeqFsOEqbEXjB+ItLaGeGcVIMelkiOR+afXvDu/lCfj3bwmLeIQ/mD9sT9os79hdSuhBmiWlxCfSVNe4LRDS7kpXdigZDY65qCpRbHvhLL3PntCEI3uAAK+ZUbTT9/LmOkiAvW8aWUZW5IbFQ3ah5b0lIejCqUS2EAu1xkB+8aBBMpHsLpZ+DK1ShQCT6I45SJCk1XbrKcErl145/XZj25Ub7WejpRK8jEX+GSu/0W4wUpCymMQ== 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=esWc5rIYrO2nyco4iv76jP73u1y8V7yGOLl+U5JSHKE=; b=w7clI7gBxL9DPvl1NscA2lV47vmPKaJQccUgL+oxsi1yS4VjAG6HkEhV+auBdlWHI7I5dYZKtuexY8w2Q+2yLIxyqQem6ts8i1iwuLJ+uZP6bmdIr9qfH7iU9H6PxBu5MYXTaH/K6h9BhOVBRLA6vKbt5DOEFMFcAzS3XpZemi4= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:40 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36:40 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, John Garry Subject: [PATCH v5 01/10] block: Pass blk_queue_get_max_sectors() a request pointer Date: Mon, 26 Feb 2024 17:36:03 +0000 Message-Id: <20240226173612.1478858-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH7PR17CA0027.namprd17.prod.outlook.com (2603:10b6:510:323::13) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: c0eef075-3715-4590-ab69-08dc36f17d78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CozwIOgmiEzMJIMi01eZLh0n2ZOABrsgKihXgDJ5KcFXsa8hWeXgQlgHvg6PhxALCj/i0H1OpjhKJFPVG7o+uXy7Y5/wXhQ4UArisQCXhFCku1DbdHfmLrmxatGp/Ns9VzP4lqzPJ3YG7NEwxKwsqZSoPUYYHgMNkpe308Dvpr0fT1f9wYvaOmtrZfJOl6Tl7DZ9fOgGmb/ANJww5hYMKIk8Yw/rOoKbvvxJIBysdsA707eetCoSndmzKt9JxVHsFOQZz15tR0bkNb6mCnkDPY5hbEkou8/CtduwQ84RZa4j7mV4gNoen4y0CcP4hc0Orn/ZewsbT0GJCCUi4mI4eiapnpmpQMZy+DvIcxuj5sTi1WjzmJOxImWhbLiMFJTvjJyLyEJbsD4nLGKJDrlyUM86/bD9/9mv5zPG6QR1hxatBxV0yTlr2p74Pq7TTFuwrM94HTfdYJm/CRbvclpLXbRKd8qAKYaULWD9oQ3oPk6jnPS+1BsgOuJ1OjYMk5VOPyTGgw34pUVwTWyumnKSrbHI+dL5eneTTcNB5/M/uZ8dzGyr0LadPy33yUxKnuK1uch37IANde0Tz3lB/RErRymN7EYgqORC52NW9Hh69D6eF7IvyJ0w1Z0If1nHIE+woowNXMRA5MsjrzPeKcAWsGWRR9AT5xBuwNrj8WTIhTzRNBSTB9MXJcVuPAErLA8FdKqtduNhAjKAMLT+puGVyQ== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: t25WHCaYTM775YFfzdRSUwpvC+UUbjpI67aEF5SOZCqOGJMjoAvNQmP9pp3rYwTHCn30By9L5DDfE6rAbiFQMrc7kwqY6bcUbHlscHO4H03yjRhu09kN/32OBA5epO5QKnPc4s3Gg+ZVxZ5iyx5KXUwJeIt2PP9MzjR5QwzA/o2IMCtfEncdkHjH8fBE3mg3bdcyybs5qNEmJVVsqaN89SN1KbqOWgLOkQvqqTKgqfCwsHIvjpbMoXfyY4z8pTRjRbHfWRM5LIDgp6Uo1EQF23uQGlLkQibpBQkBIcRYK5AWhp4wCrubfdxyYYnVjF5BryooGG6+qZ0JS4q2VSBlKWzjO33iGjlWi5I/2R3vihNoFWlBwDIyYHZEIWrigUXPVilig3P9Mbqe80ls1jSueOAesIO9utnJoCpOhWrcJief8fSC4tIHme4th6pxdxSuPaAz5qeqDDZV46t2jc9AURWJehTFl8t6R3BRa8aMEJLaVQumw6kT7+z+jCKJ7kPTVilS1QpCNdMH9VmV2TwdD486KOEclwez5tF+McJT8VlFlOK4RRxIn2vCBnbsif0iC3cFgSS9ap66OYYwATGmcX4xC5yCe43qXcUI6F/n2ZSHXIe2Yv/Y7cZG3kfBUPsE6a+XHnohqhtL9W5tKaoojNC4VK16WfeCzvr2S6P25f8K61yowO+tDwyC2GLtP1QngvFN8VO/KCHJupsElMuVziIIaZkMCx91ehzKF8IKOAjWCOzLSdnuDVe0cq9AWKM8weFCVAgKEOKIr1VwkZ6vL1X0l9GOdlKW+KApcOl+uaBAFoaxyp51HmTotGkzlZSV3z1aBGeb/blyKMYguElkICpu+0djpvRjQ1g0i0xuNIMRe05ZclSIEl1uQk3eQ1CGxwOUTXZSirZlmeIWho3SKKMw2N2LqfQHbUurrJ6QFoV6HPfC8BwLyiO05o4J/fNjqZRBnMqylAhpFUUcK5xcUq3rdgXxhkxpX7uMgxLZ22w6iLzBptBM4uknqTDoxI/+i3oRT0BmgXiBBisF3Kj0JdmLVZyulTAPTMvthdY/FvRue0tGRJnxFYkYbj7OGGr/FNIwaZ8HzI7moFR7pKQRa4YaLwYNgZ7b3wLG0FcqGzLEj+iyIt5bnJstzXUsHpif7FNrpikzV8JCWG8Es/B0uJuICjLXLFtrRjerF/9C9+GQg97pdJyWB+2WNs2tmlymKkk39Y8tkWgr93rHwmsoApnbyJGIwBE2c299IY3/zrMLuSzHG58OfENpBClpnhUv2txkmoz3NOrWHNmsbjQmfyRNKMLGipSrgVWQxT8IvuEOx2DcVR6tFjbvcTO7Fb9fsN3kouBDLXteXitDNIVZjDJNtXptLO0RVALbjt6w2WXzed28Vio+X9mu13mdc7fb/mRJszmRx9hF8LDYWWdQD8eYsq1OvzL+iNUQ0VX1M/UTaGGFO47Y0JsEfL56gm0SoOyo5XEHdV2VEsRpWce7gY9DFI1Jy7HOSKZjohN+D2w/D7iiJX3uEMlVOt33VG3eJrZO9MkH9sXOzhLQRsyF9Dt5bFkqoKuMwRBLNPfn068m7m1AS7H08VbjIuP0N0sIccKyr4va1MDMHcweTXD8rw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 3ze0TLp1rAWocLum4RTHbpdKxskPqaSWrHfDqFeRHibV0PWOrEhnQae1x9U+f83FUXmFlpi2xTO+cy3KE5q6qOUpgd7iHMq8AzElKXt6JrmrsbMtCpMcXdj6CXDII8oj0i25m2jII3m3N76q80DXTCzC/4SmLEpMws9RKy6zlcxAOAa955Blk1p0+lwF02o5vByp3/Dwi5HrWqxWTRk1YPTpleK4b8muCPa8FIJdbe/sxTuk5GOyygHqi0Shnprq8OOx+XT5usCtqZZprTGwYqS1eA9ph1rYxEk9T2pykqDOA8c4PSZ6HoHFYNc/HbsqhmjWIyQJttysL1IB0EbrqPCkw3uPcAFZVWwSd4p5U48IY69m7nM5k4xgv1sYnev5nhzVfiJSDFd/Dd9xCukiPQaiWAZ+4jnqKHZ03gpoPu1/mrtH2IV6LooGi5C1yG2LfU0aWPjutC0YSTr3QA7pyirZZENJar402fd6YWk3K5iWCZqTPWeATbKDUAHUKxZoIjcp3+dfI03/IKPXhg4t1v/YEQomOqadc6VKxdmiQdYwP2XqO+6yVNO+qLnd6XNVaNoElPMZpjvUUDXZbpfooJVctrpWwY/wGx4Mm/ranb4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0eef075-3715-4590-ab69-08dc36f17d78 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:40.0902 (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: Xat9IJIv7kIiPIzDo4YrZkWJLO5Pa2twUylrQPn5WvWDsfdBfrxEdKsB2zi/ufBxB9QG8WcSRyJvwE8JNtIccw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-GUID: jO0-6-8HR80ZRamaB4qJbp5W8yiw8rC1 X-Proofpoint-ORIG-GUID: jO0-6-8HR80ZRamaB4qJbp5W8yiw8rC1 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 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 2d470cf2173e..74e9e775f13d 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -592,7 +592,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 2dc01551e27c..0855f75bcad7 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3046,7 +3046,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 1ef920f72e0f..050696131329 100644 --- a/block/blk.h +++ b/block/blk.h @@ -166,9 +166,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 Feb 26 17:36:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 776136 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 699E212C55E; Mon, 26 Feb 2024 17:37:27 +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=1708969049; cv=fail; b=Xfs/ebGENnrsETrMkv5A3H09gLrX1FgyPCnb0LnKEwEQCIuH3yIy2D3OWJ85/obFVvU+T5WlyPNjj+CojrbMi/ziAOAYlijuaE5wQgZk6R7CasL0jfhi0xwWHzzVPhi+jDdDqOurDw7WMu8fxTdJVdsHqR/oyB3pwF8a9njP3IE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969049; c=relaxed/simple; bh=zIoU3/EuT+G6psR8/SEtCUH1Td8wEaAFcfypUik1Xz4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=dLnJcKkRXXfGHMPepdawJyu9M1KsFO8zMupi9LQTVSXIWIw9wnAEE5qs2K055JqNvt4nRtUopixwQmL2fVOaLzbwcnyIbSWKffj4dW50qP2mSsL2Pytt9aVvMjgfzcKTtfFMksx5YZNRe9UuSl0rLB90ZxVbpPGWh9PQ+yVl62o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=hyhZBblb; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=EScKHqJm; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="hyhZBblb"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="EScKHqJm" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnP2V021423; Mon, 26 Feb 2024 17:36:45 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=Coa9gYE3QHfYsDoksI78oxav6vW7nNHzCNG+kE95xZI=; b=hyhZBblbcQ+K/0xHFlrv7zQDiSNjM4OTIKHX6cUx9gPsKQYxp43yX1lgwZP/7xDBae/t 8+7DbMoWzVWzXhmn1FGhlxFJt9uy5baBOM6jBoPoDJcW/Vk8pg5wdZHzGMrux0EZRVGm oBxXu/P3dmpoSyBDPxBlVbQuRHOgoG10e6hitsdTbqodd0g4ZpB95AlfF5abKJSZ483F 0JwEuBclsCGBjIKhcKHDfLMIxvWy6v5mZzzWhpyfdT2QlfhGq61fMzXzHsZbB1yF074C naWZpZmclEe48QA3+LvJWtsTN6uGlbzhxkrW70e97QdTV6gcyBbPNLv2y8DFFpcFLNK8 ow== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf722d657-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:45 +0000 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 41QGwcM3022363; Mon, 26 Feb 2024 17:36:44 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w61t9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mnI6avE5WRk2O/fzmg6S+bwxjiuK86b5jUgG9Jp+d8bv9GReAbD2DM9le1NJI5+537xWhwaEsk4Ih7HxCm2T2ahI2f0LQuWGi8Y313JMD5TxSPHOlY/VexaH8d/O2nShsfCTi7qNBLP2jat9sjMw9OlylDkMzgA/DZ3+D4JNrS2X+nekFR6u+RV52LM3jSF0ky2isNyUYG2klt+VBEcc2dZxgpYBA3qlYXBm1pjTc7rDd3aoFKHMP11h852yv8JXuYEay0o6g4PG+MJerA/jZYpO83Tf+PtPMHKglB0ch16WWitd0PW4+g0tmEk8nj3xwASvtOyt6WZ1qETv8QXQvA== 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=Coa9gYE3QHfYsDoksI78oxav6vW7nNHzCNG+kE95xZI=; b=J/9Hp8uA9EQSeVp4YfgwjqBF1qLRfO90x4JsHrgYqJPVpreM3lpTcnGBgWp2fNEo9JgtX2i6dfgLmleMpSGMrC8T0eFYI9auWAuQhEMrypJPqcbBZ4rYRUEgWG6pdii8N7EGcOi/7+oQz6AInSt6Jl7lpimnQeH6DpROZGwdbhKEz1G3PV8cRe0AH9Ox+EpnFTBkvO5ZCij8l3vkCUpsdCC7etSiQct6QMxPIoKBV7P+mEqrlv8dHY/OJdZimO01pL9glHn+94PtMAHWnjU7FahuHYnJ+iiPHAmW9/KxUcRkQiTrnpgjk8tvt8G6v4FTcmll9x8ifrCDs5Iopio2zg== 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=Coa9gYE3QHfYsDoksI78oxav6vW7nNHzCNG+kE95xZI=; b=EScKHqJmy7eSs8Y6pvckEAZrTDf2D2RaRSjcv+dmYR+wGTMmmZVTYzCdZCmniJ98GUPZ9ZFg0HN2wjXTGn4/R6HgnuTZ4aVCAqVRFD7ggFjztQ8g7D2z29ozTlRaxEp8wZ7aKO7+9wLFhqx4kKJUtLsji87qRH/gcSB7CnFyVfU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:42 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36:42 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, John Garry Subject: [PATCH v5 02/10] block: Call blkdev_dio_unaligned() from blkdev_direct_IO() Date: Mon, 26 Feb 2024 17:36:04 +0000 Message-Id: <20240226173612.1478858-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH0P220CA0027.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:d3::10) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: ec86ca45-bc3b-4a83-3e58-08dc36f17ec6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ux1GB5gtfk6QUygcidjaCOAnwhJLgwKzwRNZT2Y/uKhh6n98vZ8k9EQ9xtpz8RTvoqTmZMXSNUK5pj2yigPLYMtwUI7rzPo4ywD0Zh5NzPwW6l3+1PSp+Zuj+ijemV/Yw35QPweyr5ovyrVqe+1Oo4jbqzooLEPTq2clJHX/qyf00W+N71fi5J18wfabuj2RhC+Zj0oVizxsNnP/hMRQCHtdk68TKPcpEIas7D384xMPmRX+OyXjjB/Lwts8WBN/+gYwhFKGPzNF7syHAYJEaiRv1IRRr3jpOSmDzKmKUeFbsZZQ25k/xgSFoMq+Cl5snG8XZDqti4u1pznjUrx7sHDQ8A5Pa7g2QENFBh6nscaapPaOLFjcXXfToGefFnI6bRRoMrVxdWPb/TBtMmHfBsOhLyj9p4/1fmcq2qdbh1OqtQ19EOeQ8n4pZT07vHZKxTBsr71cz74pmkFoXSuCIV8Hdq0yR4HTrhkvZRMDXgVNDL3bNSvz12Dk0ZP3JEhmiSExukV1R307fvMg97AeYYW+i5uIv7KQF2VMwAC0DSiUR+zx9Z0JPLsBI+XNJ+/GcM/8qcY3N+Hd+IMD4odZ66XaPbQHSj7/XqD5vFpefsVWXs6GEmMcop50a6IuhAMJphkrIw3CUfj1WXjd2ZytGRXwtKkX0tCXFy9TCtWqgnGdFVRekhzpn8dKoSLNRwXgj3vD8VcAIZNLJi6/aMVIww== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uZR/wuerVa4oDaN/SxKj0dZV1hMD6i+X5V+T3UFi7qP5HgNa9Q1NVrE5r9WorKx8Cz99DCIWwJxELGEjVolrhpxLfZOzWLc8EB3LffYXwfgKh7GW+vEB/xoQb+hncrvalCSxL6CGOjJ6nuC8UWzd0QHKYEKW8jsC/sd1wEaB16STMRYWzTAyljGsw5bzjwq50iqHBH0R/62NWC1f8wofL/7p3dVFkocyHxQviLXLy1uqMYkllYN6u+8daGpHHGrinEGjQ7bBYEFTH6muSXmBF9vI7AYQQ4+T2FDgfBC5xlMkua9kz8Wb9bOELEV5X/+oWHIuPZEmcbfEfoVmU+YwgtlvdvGeET4BiJBYVwazynZk48DsLciuNrdDE5HMGJNGZOKYVrEha4FbIo2NyE4MoOzL1zTeAL33rHFz0ThHD9FmkWFNhsejgpdoYHz651XRvZ1E8hKBUTy9Fx0a8yhhba9vlt3NuwVvWKGEcu8DSbUuSXfsBULWed9kyOwHXsHTXj0BqeWEQZ31RAPDntBfq6GKImsI2NCyzrb291R283pzVze4IzXBjE0TcWbPStNvsAZzUjTGRLYAONQETJSlBG8kxq9ZL5kmRP6oJDsc6k+U0RtrcAKGVbB8qug0GzJwjJZrM1oX+ufKlBn7i9y/2aPpS1gi9Ml1VndJZzIZD1RJnN4HUTB53hM597UK0UvdOIB0v20ltUDJKfnHJ07WudTyx78ICsfKXpEIdHMeIDwCGvwqQY4UwzizqFywQOjE/acBjYlQ66+TN/kb/yfnik10+l+8I5fE4rcMjovrF1F7H7k4M6JGGLn6uh9zgSH0n5ns1nBVBOVZ7blp/XBtaFVg9vKvgJQiDDVtLOA77dBOKnDiiTM/4snKc2lczBMyF2nJJwKrNimg8s6i9Mdjd2XAgS2xE2bbrVTyOSmndWWJSi9kwLuMBg5flnr/IOfwRQmbhckddOFdwL2jE+zaxIF2TsxJLZGnU4dFjwZ0Rqo/0lt3NPqR9+mAHESfowQZmLE+XOI1qJgmgYygb06CMqMRTMzvl5Ue9stoSTOgfseOdWl47PsylX40kP4iDaNxStsenwi/4UttlbGEQYHQYjPNDeXCoRLrP/+5pMP1dY2pPN6pfGUOyJchJftXIAct4olRDsMqatHl0AdfbSlU3VKWX54k2VSSMhE29OfErgPZgtL9omVLJoVnFmxKhTC/vhFF6cazMh43YM+1zswf1Lt+edqEUWWTTNs5BUguHhO1s76s4lLR7Zd6fyMW2nWUPSNZH9LFg1BDVR4vDH7Bu108VAi6rSOGfk5jhVgNWqGJGHRw4cEjKpLSeaXemXPhno2MXo+QALbBtPlaee+sOxAZVE46UZ51d3UwPeS/wQIzSLykx9oUR+wG0REDiWYjev0KFt9eM6efbLZGiOuSSMdNb+t3DYxUDTfO2R/rjGa0+LKi5dme+RU6WXFoW41pWoIuOqtDR6AfO/SLbEg5GzS+bd+gtqJZIrW8cJFIw4Lg2EcMPKRohpDIZcHgxZVXC7xmEIJ6ha/iKdN8Vhyyfa4iMd6Fv6X7pK4yvbsj5RkFChRHabVbZ7IfxUsCvieezA1ACJWWW8IDcU9YOsnGMA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: N2aOFV324Av+ISbAGpLrVs43WCBsz7GHu36mo1w1cG6omN1s4dippo7ovtRisweH9N/eHVz5P8oqaAjQCJKoJ/2s+XDZZW+dJBMSXRyVXrpFQJ8S5i0eaIKZJankaMbnLdUweC1k1fXb8L6LvlB3LsAH14gsxeYRK1NYIDi3LVH3Qs4niuXtXldLg5HlGvSjkOA+0BxFapOG9UjdhDL8rdGV03tTzoBVcQ7onfJWi+0ayO19Bh5eOrItqoIQzjnXQUgcI2QBy6T1t7bYqbyOJyVlcfKvJc0H8KoWVX/qf9o8YQRphGcoCm/qELPuOhHiyDYHWc2ef4ZcmTliStA/fVSwl4y2VasodifwP8dZjt1Xqm9V18QtZc9dMHlMu+pTSF4tudyl5KTOAPHOVFRFh47n6Qys/Etfl6AY9uqGq1+HegaU4x+6uJwY21tj6bolCl+3cCkdoJ4Mz5SzMQnrX8em49ylKsK1nvgTNxYEWHZ+4biDkhL5OZOFUBdQXbfiA0saenriZDfIFc68zyZLPzKV+8ZtabY4GS09dltKeuiMqoFuAeqxcNO3ishsBeXSd+Z/nMjyb6qaNLnqBmjF29YLck1kpZBbVmjVFLKhzpY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec86ca45-bc3b-4a83-3e58-08dc36f17ec6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:42.2526 (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: nAmIXPyEc0lb9LZDLfyvA6V1IkZsT22foLObW3GfLLP7INHGDoV6fiBYrQkEcw0mfHhgMaRDvNczgMuJBKQ4oQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-ORIG-GUID: 0CyouJ1CFlKPERxj29i2nnopRWW5Yb7t X-Proofpoint-GUID: 0CyouJ1CFlKPERxj29i2nnopRWW5Yb7t blkdev_dio_unaligned() is called from __blkdev_direct_IO(), __blkdev_direct_IO_simple(), and __blkdev_direct_IO_async(), and all these are only called from blkdev_direct_IO(). Move the blkdev_dio_unaligned() call to the common callsite, blkdev_direct_IO(). Pass those functions the bdev pointer from blkdev_direct_IO() as it is non- trivial to calculate. Reviewed-by: Keith Busch Reviewed-by: Christoph Hellwig Signed-off-by: John Garry --- block/fops.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/block/fops.c b/block/fops.c index 0cf8cf72cdfa..42955b6a1f5e 100644 --- a/block/fops.c +++ b/block/fops.c @@ -44,18 +44,15 @@ static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, #define DIO_INLINE_BIO_VECS 4 static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, - struct iov_iter *iter, unsigned int nr_pages) + struct iov_iter *iter, struct block_device *bdev, + unsigned int nr_pages) { - struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs; loff_t pos = iocb->ki_pos; bool should_dirty = false; struct bio bio; ssize_t ret; - if (blkdev_dio_unaligned(bdev, pos, iter)) - return -EINVAL; - if (nr_pages <= DIO_INLINE_BIO_VECS) vecs = inline_vecs; else { @@ -160,9 +157,8 @@ static void blkdev_bio_end_io(struct bio *bio) } static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, - unsigned int nr_pages) + struct block_device *bdev, unsigned int nr_pages) { - struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); struct blk_plug plug; struct blkdev_dio *dio; struct bio *bio; @@ -171,9 +167,6 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t pos = iocb->ki_pos; int ret = 0; - if (blkdev_dio_unaligned(bdev, pos, iter)) - return -EINVAL; - if (iocb->ki_flags & IOCB_ALLOC_CACHE) opf |= REQ_ALLOC_CACHE; bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL, @@ -300,9 +293,9 @@ static void blkdev_bio_end_io_async(struct bio *bio) static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, struct iov_iter *iter, + struct block_device *bdev, unsigned int nr_pages) { - struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); bool is_read = iov_iter_rw(iter) == READ; blk_opf_t opf = is_read ? REQ_OP_READ : dio_bio_write_op(iocb); struct blkdev_dio *dio; @@ -310,9 +303,6 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, loff_t pos = iocb->ki_pos; int ret = 0; - if (blkdev_dio_unaligned(bdev, pos, iter)) - return -EINVAL; - if (iocb->ki_flags & IOCB_ALLOC_CACHE) opf |= REQ_ALLOC_CACHE; bio = bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL, @@ -365,18 +355,23 @@ 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); unsigned int nr_pages; if (!iov_iter_count(iter)) return 0; + if (blkdev_dio_unaligned(bdev, iocb->ki_pos, iter)) + return -EINVAL; + nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1); if (likely(nr_pages <= BIO_MAX_VECS)) { if (is_sync_kiocb(iocb)) - return __blkdev_direct_IO_simple(iocb, iter, nr_pages); - return __blkdev_direct_IO_async(iocb, iter, nr_pages); + return __blkdev_direct_IO_simple(iocb, iter, bdev, + nr_pages); + return __blkdev_direct_IO_async(iocb, iter, bdev, nr_pages); } - return __blkdev_direct_IO(iocb, iter, bio_max_segs(nr_pages)); + return __blkdev_direct_IO(iocb, iter, bdev, bio_max_segs(nr_pages)); } static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, From patchwork Mon Feb 26 17:36:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 777724 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 5FF24132494; Mon, 26 Feb 2024 17:37:43 +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=1708969065; cv=fail; b=seDcERFckVD3UfwlF/x+pp7CFw6h7ILxqXu0D26aAt2XsQfZHEN0tmOcql5EOTZ1MSyO6T2LMmgQIMABa7hpPiI5XrApI0JOlwyc4hE6B7oRQQLxc93nkh9sfFi0LsjaNpejLIz640APcIm7upEdAyJNMoKHezCB6VTey6UaN40= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969065; c=relaxed/simple; bh=T4vTffpf1rDy6pFEykqhB+LYYvr8FjI4OMHj/cynNyU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=T1U3aB+O128rwrqN3o2YrgTahZa51PfGd4u3FigAlo1aYZDx9nd/yC2NuAgM3GtF8hCrpCuSG7EgkFOdRKhAWtv5U4aqqqzG++zsDjKGX5dA7wCo52W+MkM27k7Yiv9+9+U/YEnOUe1IWTY2OuvoVe3+/+8q+iAJogdUcnKwHjo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=JOdXcQBA; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=E5cMCfwS; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="JOdXcQBA"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="E5cMCfwS" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGn7JA003771; Mon, 26 Feb 2024 17:36:48 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=H49hyexlIrSIzWqVIejInFGx1vUNRq0ttgLyNxUOkKc=; b=JOdXcQBAwQalBJxBgMmBjuHIRLl4Knd5ikPCSnX9kAWHGRDCmCLojMyYyzdBy5CBFB5u n2gA5m/hBxMfVEvSduhqr27U9Sa6AC/36QS4mLp+gmd+WjFivc+bFHU7a5pA23TOasuU 6FYBn9FBKb8O6XQlNhGyDKukoHFS+KR6WAaJYY3ddtxGeXMNVRx8TzxK2tnp9rgvwzgA D+Qztmmhm063LVlVuMwkxgfuMu6Wmg0ESc+xMcCGmO4vtwD06qSg4IqC4yWs6i1Q/a9S RYLx7DJbRcU4Fbll/8WEH4cWitI/cqScHA6P6gsvWctqnW9o34Gx4uQ0n8lyLUuH/n32 UA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf7ccd5tg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:47 +0000 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 41QGxj3l022406; Mon, 26 Feb 2024 17:36:47 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w61tbw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=atB3SaDz1I6lLtD0Nj8wYYykFlFdfKoixFBRiFUf2O7gfgZbMKCsjgGWb1PajPJSsONmZOPImG+KpPkoi5+WsN8CwPnHWSQ5HIXIKZxApBuXyQXUySKte6ugWv0MaeSL5KDE9qDABNiy8UWXXC8EiiGzoBJQqqmSMGKvmpTfm9m5oSqOZUBHHfxZ8EB1SYPrgMCDE1OR18PZMFjMNd8sGCcuYaJ9pwGPO+J0K7iKc786m6r6Ny2fWYZFG4VaxkRBYvMtQGO8TLa1rztcPdDt4/JRTGzbRh2rnC1/Ywo2TVzpWgC5pb+XTfvycMlM0WvMfcqwHcq/9Dz/Ko/D+EsxMw== 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=H49hyexlIrSIzWqVIejInFGx1vUNRq0ttgLyNxUOkKc=; b=hdKAnKrSKnv5SWr/jjaTWbyRqDHwvqYk7eMJ9HfEHhYv+rY+mnxEPhOB/hNUKBwzrp93K89RomkblSb7ndRyeiQeceEORzVL4qG19rrmj25K9CKnuQ93+eTRDsLR5r48FmjIBMDLKn7jDAoT9c8XvkBqEY3HSd6/WmcCkM1ItBVTIabOnSkDHymymhLSqnOHt/e/Q4s4xwU/kMmJCCKGYJFEroTwrhkGb4VEQVZCxvUYbKgW0YW5r4JX1ZusN0kfcyFc0poHQtWTvfIYGPejFZqx3M7Ral/aIIzo24zjQ5fmosad824ZFdOvrkQEjddJokT19/2GoJcEh1IRQBiyug== 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=H49hyexlIrSIzWqVIejInFGx1vUNRq0ttgLyNxUOkKc=; b=E5cMCfwSgopf2WCFr9nPTJCvjCcv0zxG7dI+1pBZQu3cB1Hqdh+r3a7geJVcNNcGjfFXhHvNsFhhHqhrAphtUzPoNRLRwaFvEJyKm4401GueeT9OWqtlASb/wbPId6vRpOPjSCv7D3jPeAOgCiolpSAsAnJXECs2EDfM3b/L14w= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:44 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36:44 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, Prasad Singamsetty , John Garry Subject: [PATCH v5 03/10] fs: Initial atomic write support Date: Mon, 26 Feb 2024 17:36:05 +0000 Message-Id: <20240226173612.1478858-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH7PR17CA0030.namprd17.prod.outlook.com (2603:10b6:510:323::25) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: 87b821c2-4578-4d4c-5def-08dc36f18023 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QWPslNKHjAipYkpItrXWv5B2TCbFwYJlCL9U1EMTl+aecKYVlQaQz7RudInz2QK3MdEBu4LvWZk6TkYB2SA9/rEDapBU0qkUIwACOcui8H77Cwh2lHc35NRkLWjCD6Wr7uDKU53SNlEII74JLNCx/mFOAML14jt9tyL9/yvtHJQRiIAqPyMFkDEbE4uQPlH7LVqzL1fqh3PbURTUqMUuSBPWsIaSMOtRXeiBVdmEXjqoNxTaVjoFjLpjptxpIGrFpwLjv7DftcJ6sJvneSWM5S30v2rurqLgdWfWnjTya3y3mbGi5cSFKKrufM/8MiTuXzKV8UUAYzMK2cJ4Uvol5lwZcHQi8S6NESfoMW8I8PwNyN8+mSYZc5WDcWYFI2JdILzir8qQ+e7tX0GsqLW9shslUGvZLtIh1UTOezghAiWyRcrky8LKMrCs8o5r/4zct6jzxdUSFFGb92XhANyR/jyRPxuE6ACh1Tg76u+BpwB/o9mpkQbmmeXTB9Wp30ODW63KzqOOJ6AZnYzjetjl2Ot51BGwnFiqMMO89vHgIJPQtCVs6L9ZQLDXIYfcembUUIkpzueAY/NuTPACIFRNRUc2/rPAMg+fpMdBTVWXpgRmBfCSM4OploltxJND2MEHShNcJkz6vl2QLRewCQ4jOH7mZkXCKJ5mmx9NX4UcSJ0xbJbb+lhUmIqBqKW/U4vama8xGktneWFShrzwL4pz2A== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UWDDYaukj/qbMgoFwCZLm+j5cuFjObHNK0F/jseJ2UDmSqJtKTBH1J/6dynCUT64jQU+6Cbc246jvbQ0buW+h4cKaQt3M7aUskxBAH6BR34dxNhEMf8/6GflYPA22mILH/Sh1j/NvkjZ7hTFHMII3dgo4A9xbvqHP/Yav+MYmQbL8hwtBqxA+ieTBWdR2DvY2UMrqYve0An4suNHJNOShxIlnj9iujBDWkKTdyO+rho1/GyaQoBnGjyOev3Et3x50NDzdcv++uhqcP/q2wNWgIpzp1GhWEVoJ+SB1WyTsagHLEoUcwXBjlfLVcQoc01QpdwpxqpOl/jmFRbl+JcFnHkx0iHHnMqZxTpvvzVtcCJhMfbY1YsTITqnNHP4jVc5/gyXZWvZRj8A88I40pjPFP+uV587Ig8ePb+uHCDoAyDW0+PgBBLvWZyxxOmedCwauWh0DqyaFp/S//qODfd41G3L/eZ+jGbCRbKXd92sqVDu9T29YRQEfrXpvLjS1ufxjwK2zJ7iO4Rwvze3fgAGjTdOvw8J5Jcjdyj0fsa0sVGRWALPOt6dooKKo6QcMH2Uhg372DzjILuDIyRajTx71jmwQ7cDSFa4AlynfWvk7VhlgqiO+GotDHu62kZFQVLlYbcIbGsPqWqagQIqW5DlvDTgSCBIUtIDU+FpgwZcELvMcjKqlJSihEdgi2T0Ec+LHNUqry87GqMYhCU1LD1y/D2mv9MaWMNWI7vopu5cH8Qfrji5v1qMumlxv/l+OdyOaQ2/8u93S0dysG0L+Wp90Qkj4j7Lwjru4hiwMLPLb7t7iM/FKv81/vZ+SL/cqIPPkpbnwbcv0/NRN8xmcxdBqiA0e0e0KipFNCkwWE7FMgUHXBatrafeVBcnpi0cHKNTNn5b54JmHmYsgrFeC1AKX5+hJL+p3nrsPDM9/IQy+jVZ64/AY8eHr4wdUhd8L+TlQaejDZ1bjloXXFgDknI6ktGe580jiaC7WDirkN3OnqolcCMgQw4wLDnW2rvoU/yjtab5sXsgkywC39/Gz3b7wsuxVfIu0IYmYmxeWM3gGPdyDygHkkcEb+kLE1obMbzbRIxNBOa3l2T4oHoo1X0SHdChzYPmoLY3urXVA7q76oVMiJdj1Q1bdoAOCaNOz+KcYucuINum+ILJ3Jy9lxUtcCro7qVAErTQGZqW7ym77JAAg4ugfVSWfTFbqPXzwpDAqeUneq5fxMnrjCEVnGMe9yYx/4Pz3WExMjY4w9Fot+PKM8Uof6SCLx1Hc6K4DBpVCqoLSa8t/7VnNNc02sg2650jgWcXA1HFe+TnZDOQPJIGsCDwxv6VgKPoyqvv+jkpDXZm1A/yJowH3Qx2iTJoJkme/dDvEEQ1reRlKw0RYVHl3YjPw5KB0KCOW+B2XH641PWo3BGICJ3yY7zlLDRdgoBZfHZChCaDUf1PRZ8LcEs93BJLzTRFY7zeXRqOJrVAmLkZdn8C67Cobm27XbaF0ynQCQlkx4FckzZVrWU3VfF8eAjcFYo9U5KmtK73R55LUlPk4SqEAfGkQTAY+fhMKfZ3/ljB/KBrknX3WQrP0ko+txyUH9j1suRS6TK04Z7IFGrPjDxrgUVV28WyxmS+qQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: oiXN7tD3DJzQboB6OtajKWCSD7pUPZ5YAbk4L2lGwzBTQbqBdZYGJNXZ7/VwXQg6h0u7dB8Ue3X7/VXF8IIDTxiHWJhXxlLUx9fuuzyKnMfmGNDglog0iamIyCQdYB/pp9ShuEOLSujHU61abOfK7iEUmkmFJVPjz8sPZVihIayasHo9rVGstUpc3vsOIw2dvUbdBn/+ae2aUgrPvfdxBjjnReLKhK9m4jcRCP/ghJkGzUUgp1vahaFY7Cq+dlV7aZk3aH+6yfgAbzQPmUCYpXKgOb2uAvV+lT4hsUnX1X3nUCwX7Rlgg+Cn9v3dpQr5h17gxCs9nkX+MBOBAASYhXPNp6Nx1C1x0WImibC+p14whxgBNT51+FoZZnKfHOYRtfqXlPDj/60q8SFtcUQiThFcJeOk3sJs36gb9t4OYCUGdZFJe+D/mOnSxig36FxfpKz2law9MEuo25U1F832wF9OEe3Yq+8ovbuD3NNNvD3J0hKOswJs7mhjaGKtmdfGxW48qDNiFUzs9odbi/+vyg+Ur29FN3oav0PI8b7k24IyxXRbR4qbEYZbLumufenshjeuCI7ohUtblfKiKDaITNz/f+kcSg5Tk6H2hewjRVo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87b821c2-4578-4d4c-5def-08dc36f18023 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:44.5990 (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: tNQONJuh2lVcZGZ4Nd3cvfhKuRKc4Widv+/ZAJioAA/wQYMFdJlbSNBru7VwbJoKxfFZbaXmE0iyv18k5Kh5Sw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-ORIG-GUID: FKEnblygdTB8qwnfZpf0aA685eT-S2kW X-Proofpoint-GUID: FKEnblygdTB8qwnfZpf0aA685eT-S2kW 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. Signed-off-by: Prasad Singamsetty jpg: merge into single patch and much rewrite Signed-off-by: John Garry --- fs/aio.c | 8 ++++---- fs/btrfs/ioctl.c | 2 +- fs/read_write.c | 2 +- include/linux/fs.h | 37 ++++++++++++++++++++++++++++++++++++- include/uapi/linux/fs.h | 5 ++++- io_uring/rw.c | 4 ++-- 6 files changed, 48 insertions(+), 10 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index da18dbcfcb22..ba420faed82e 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1509,7 +1509,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; @@ -1535,7 +1535,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; @@ -1587,7 +1587,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; @@ -1614,7 +1614,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 ac3316e0d11c..455f06d94b11 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4555,7 +4555,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 d4c036e82b6c..a7dc1819192d 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); diff --git a/include/linux/fs.h b/include/linux/fs.h index 1fbc72c5f112..95946a706f23 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -119,6 +120,10 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, #define FMODE_PWRITE ((__force fmode_t)0x10) /* File is opened for execution with sys_execve / sys_uselib */ #define FMODE_EXEC ((__force fmode_t)0x20) + +/* File supports atomic writes */ +#define FMODE_CAN_ATOMIC_WRITE ((__force fmode_t)0x40) + /* 32bit hashes as llseek() offset (for directories) */ #define FMODE_32BITHASH ((__force fmode_t)0x200) /* 64bit hashes as llseek() offset (for directories) */ @@ -328,6 +333,7 @@ enum rw_hint { #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) @@ -362,6 +368,7 @@ enum rw_hint { { IOCB_SYNC, "SYNC" }, \ { IOCB_NOWAIT, "NOWAIT" }, \ { IOCB_APPEND, "APPEND" }, \ + { IOCB_ATOMIC, "ATOMIC"}, \ { IOCB_EVENTFD, "EVENTFD"}, \ { IOCB_DIRECT, "DIRECT" }, \ { IOCB_WRITE, "WRITE" }, \ @@ -3323,7 +3330,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; @@ -3340,6 +3348,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; @@ -3525,4 +3539,25 @@ 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); +static inline +bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter, + unsigned int unit_min, unsigned int unit_max) +{ + size_t len = iov_iter_count(iter); + + if (!iter_is_ubuf(iter)) + return false; + + if (len < unit_min || len > unit_max) + return false; + + if (!is_power_of_2(len)) + return false; + + if (!IS_ALIGNED(pos, len)) + return false; + + return true; +} + #endif /* _LINUX_FS_H */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 48ad69f7722e..a0975ae81e64 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -301,9 +301,12 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO O_APPEND */ #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) +/* 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_APPEND | 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 d5e79d9bdc71..099dda3ff151 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -719,7 +719,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) struct kiocb *kiocb = &rw->kiocb; struct io_ring_ctx *ctx = req->ctx; struct file *file = req->file; - int ret; + int ret, rw_type = (mode == FMODE_WRITE) ? WRITE : READ; if (unlikely(!file || !(file->f_mode & mode))) return -EBADF; @@ -728,7 +728,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; From patchwork Mon Feb 26 17:36:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 777727 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 5D14F12DD87; Mon, 26 Feb 2024 17:37:28 +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=1708969050; cv=fail; b=gaTKX90Tph7BAJ2D522Up2CzkLGjTa33Vd4ED3GnqsvSQGFrk5nXSJpV3rfNmUm7jfjVF8xq/iIFj6dVufMlM6Lb9Y9gVrzXIjQ3fBwOz/bx7I3zGr05bLNKHV8lq6/sNi/H0l2benbf//2l3rdOc+M/3QAdQ8sBxpcIs59JNYE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969050; c=relaxed/simple; bh=7VtwtS+0nm52oB5qSUgZkIShsxy2sla2FnYewznMX0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=RsSgqTxtAbByLfSCIYd/WQvflFqAum36xRH1X+k813jYum/fG62kd1R1GC5rRcdy9SSEXlf/T8qOdXO9k73z+8/27pxbqcQXJXZUKG1PKOjsH6yUTBQtmtYjtC/ZormqsneZKIUkfWr370zfcqnVLCiGpWPx4qq/Skqb74QLjlE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=OuPH+x0s; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=ydrfVX+K; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="OuPH+x0s"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ydrfVX+K" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnG3p003882; Mon, 26 Feb 2024 17:36:51 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=rTpRfX6Re6BPRP1QicrEwIdjg2IWzfcdHeRheN+dgZk=; b=OuPH+x0sOsgxH9KW5adNyEj5xDRDHir6008Z726fF5BZXPEDYCOD5PR6wTI/8rcjVRXZ kHY7qlEV67MeUUme+ewKeDP7Oxlwg4G8enYIXdi3HY27asaBMUlku4tmqr+QBS4gTCgT o7ohFIv6NnUj7rBwaHcQQU5qBPwG3Qvsebv6xjMn/JronqotyF0D4EP0yF9Pa/7sPpp/ HiI59qng8HbGQ1uLc25pBxOGIABD1VYRFkpzGUsUsoC90Th4ZakmWOpukfFtK6c+o3ad 4nNjFJLDp4BZn4ZwtbOt60zDQgKfAPgHWHhSlvzeoVczxlCxL3pgY7I4C+WmXDAKdhTE TQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf7ccd5tn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:51 +0000 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 41QHOTtX009826; Mon, 26 Feb 2024 17:36:50 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w5wa79-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dgN2zoelF1G4tCVhqpUQ5Orqwq1YroOTBIaRPw3L8pBHVTPktKhOGuE3lcv8t4Mf0JWOScBxTPDYIt9hTCutCrZ9vhzBXInG8fBiVoTVkbD7cn/cUmI5VggtG4tKLi6hRdWHAzhxPG27xlj/fLiRqNzODXhkdjJxucNcV/JauNNI8vOFy8YsNJHQNAwROaNBJ9urMXZFq+LTnClZJWXp9nL3QwLZc24dFWIfn6JsEcT2qIeURNCwaCLQlcT2I5rnGgyC9wxbjvymTnqM014hHwymeMBqZ5Kh7OXNV2SR1gJXt1cjTwSi/MJyT6lM0Ba9XPNWMMenUmINetQSo5lxJA== 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=rTpRfX6Re6BPRP1QicrEwIdjg2IWzfcdHeRheN+dgZk=; b=HYq2fHy4ADp1e/FxYH1JWOqn1okPwyfm7i2Twx42M4/72ACPO1TTzHyrfe6kGJUoscFzeVhGwzHq+qW9euNMauHEwBf/OegnmyVUfk7AQGM6UR6dID7aCQdIT7Sk14yO8nva/FzEp6sEP/NlFZI1jxN8zvp1YUlruzVCWZWro/RibMvlW9S2WEx2oV5YuP5OYmI8iVhvSCuNkbETWvMTPfc6gH2GF40oNpIzd+IM2l+eZqAzVoWpPAh12x3fMp/Osyd+9Wuk3rsK6vsFobIWIARo/QZQRqjDNNmbvTy/KHr8wTY/iXxe/uM6ah2sR9JunD6F4F2f8vuDbkBZJCBuPQ== 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=rTpRfX6Re6BPRP1QicrEwIdjg2IWzfcdHeRheN+dgZk=; b=ydrfVX+KnOpBZVC+M5hnvb3kXk+V9PRmawodI8URezM3Dv2IfYOs2QIu6zXb9jhfaqqNrOKwDSg+JNn/qjp87yQ7lFeQMVZrGK4GBvc2ZE9Zx3IQIDMvAJmjzXcouncrenuzrY2LIyUUXiulPrFYZA8FBASA2bepCRYVUVMU71I= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:47 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36:47 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, Prasad Singamsetty , John Garry Subject: [PATCH v5 04/10] fs: Add initial atomic write support info to statx Date: Mon, 26 Feb 2024 17:36:06 +0000 Message-Id: <20240226173612.1478858-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH8PR02CA0035.namprd02.prod.outlook.com (2603:10b6:510:2da::30) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a44e6e4-2e65-46c1-b627-08dc36f1816d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g5WcoaErkPW+GClvQWLRjzoFRpFi91x8qzn8I6owRb4A6FhglZeaCOycBFa73kcT3mBjm1ez1s0awc5MPW+PolhmJr+VFEJjrf2YnX7LCjEU7GhimO1/0fM6mC+qEDZ61pz8Z6mj11m6sI5ED7g7Tg3xq60NCBhdTmgjpP0TW5Bvm3eUdqZOrF0KtXMawvLpNUxg7JS9a6sNscLcL1LipEy0ODd3hmYzkog4NbS1jq1kFipZWwB6o4UNjkWvvySepzVCiojeBrA3TuUa5f7rXgIX8ymX3ShzGO/MCFU8qn8WwAvZFL3wJKPh7+uYYf+wSlW7C4GKeILVjiHSmuhfVcjtbSUB/42PrKA9G0ZXcCq5jWneIbsW46l2USxMq7Nvr/81YG/7QkDvrQx9rK4eyIiqNvs+7fCCwXKkXdNJcNksCsLxR/z5DCEKTRLRyhS/nREBC/2Uo8lsEWfFLjDP9d/g154CcEDkmTBnSRI18BrRJqIyxCj3rfO9jZddRB5lZYAMoh7Cwjp9ezW8P+A/pT3RIZ20PwbwT5kXkUIOzqq3g1FnlHwXw1+2wR1vEtkOxMusvZyPgL4xivj5MNntk1iHQN5t9ZaXfWTXYEa90R5t8U/MnfikW5hsyGe9BtYPk7eLWhoQf3kNpM1GkTxcrE5gsJQl1GbQGVmNjHWtEvMWYiMmbVmTYIeZnQqQsZDtB8KBePbN6HwxlviEpAHAFw== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3p0IuGi915oa7aI84Ry0ZG+Vh1JEXzH84602fV1l98v/4JRcgphG/MCwbJbZTLa16km2UqKJheVB7OOz4x1bbNmBcm0vG62+GbUs1qQpNo2KX8EHSj2mhO9Vbi4GQu3F2r40vC6xh0cgiRZJ4MYMUQmccLhy1Z3Lge1r/mYGe3EmuBU6zPcI7GOO9wZv1QcUapASdLSgegLdxbKj5Qbni7lwX7xxS4YU6EoWTLdYBbPPziMwV8OHcSwz6D2H37JnzYcwc9LsIil8e/Ir/1jHcFiOUlPXRcEZERIKpdUDsTr9g+DVHMth2ee/5RS3BE/oXSmTlAxaCCjEK6KuTPNvvkz7rdSp9SdJCi1NfW/CQg4//dUrXPAo380RC1nsRO4maMs9LJ31C8K1QRfvrKreYk2JcBoEGZiSyN2HKPpZBrEVma93xmddru/mk/GrXLBYUyu/JVgAaogG54AZN0BdmRplWLnaWKJkQOM1ZrMrxZ75tJlq2ekWZf7QHFAoW7Gr8U8+vPbuaR9j4CSZldZiR//3iJFukctkgXrcIZgZtbfJ7cSNpZ2w3y0Qcphl/xNIrPc7hdHsEtNKUg5B67hWaugJKB7D/9W5Jt4XUJuJ3nzvKcIBhtWq5LoRC8BxQu6NcQA4v1041pzUyBs/O0/Q5SH2IGZznMru4ykyl3rTPtLeSW/HvItvyyvxYgyYgQvm/UOM4HDgNAtMmjDKVxYcQHoKVi0OjqiwBiLy9c0vwyzezYrzNjPPfNbq4e/odxZkbgtd5uDwK2myr5+L9CshfOKvn0bFUHnGTPkZLoogBuOqiuIhPep4Ru5krJkAe1YI1NGUDRnsuOvB99ItahZPKUCVDsyowbRir80rN0ZhKmB5MisPdV0SySy/6jW9rLV/5S2qzSvBSeFzlXWiGoBiuEKS/2pUI7evNKLgbrnZubnoemfZa+m9szN/kKyTpyNcyYWACUkNKiS+2sKc5DIt3H6JZlBdDMr/EY79LUgu+V4vvzXUP7YQT8SsLknL+xWaKGptX4nLqO/JSBoYbuy2bwmd1CeQ1ntSxF9+XqGBFwyJoYy/vQ/NbCQaCBiNDUt03YyHpRP7zj9wPf7WNO2QOKHPjSdipNwstw2JffeEV+NxwXKdn0VGsjuaZaP/o4AeuPa9L6o7jN98V0AjUNuP1uroCEIUOlW0GjTMYxZK/0Lzq0j6jO0dymKFdZZmj0/cUJ6zxlkkOSc+KKGyLjSHd2vv72pXN80MqEvdWWIc5oAWj4C8bA0dOQSsuye0fGTql1JcweC7e54nvOzNkKJs4MpmS0TaLei3jAHG7dF13NoEsFBZcKUvg+E/Nc3gXPXTUpnyL6lJ5Gp52fnH8RW73DaxuwTi6LBG7CAWdN+RbkXuuXTiheOe3mPooMGNbXfreOihwuDg81HSaJb9oiA6O0gfIHzTODRIUq4zPg73qt1MjlRBU7fk8J3Tm37919wrEEe6RyjDDgpZPiLmz5iwb/68O3180BlSJ7PiVSv4iC0rWKgCXnY2rcVAN4VtugAPgh1xrVgf61QvlexwwxUHkBtJuGl/ArZawMrx5TNHYrrqGQqDo8xyMn7FwFeOY0lWpn01297KXXnmHPOGPUtVJA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lrxoOcudu3BtpmjLeTItMnVfbpJgx70P/E2PT0PniBXs5N0VxXSTLyST5Zgsxg+vmPLciYvcuw08Xeh+KvO2lREmASKYZRnGSqb/zNhYCBdW/rRJOrhWhuq3o3zAFe15awa18zo2Zppq6TiizaSdlNAN9qDRRHCIxGP6hct1hEfGHjcBt0kxwVYIgbHoSmOM4W7cyasLdqrpspZJ/aqMoUNCKnvvMsZNhB/AEtomxFUMx5vzv91xgqB/QKq0Y5IpaH5n/NioX/kiGgKKGp2O/gXa0R8wf/GPIE88vL/3xP2E0G21mJ4fAY1ZTPz/iB9Bi5jeRSW+eyGqwQdbALU1hN+aSFEg8+iCo5uqHqjzGs4QHOW8celQo7M3xfY1NFJjNabVDd/7xUzIkBmU73mmcuwpiURER1wIFcJhJwZ7du0eZn6hy16DRWFmbH8CG0l0lAk3diSmyi6wMh4nH52Hl2jykLpR4Fn4B0ArDmErj9EM6WgrjDqvWsHtOKyvlqA5PYP+tab9bY8Tw8KMqkAf3dtuJFx3xBcokK9E2fAoZpXLr0wp654Zj3oIGXFdTzSbivCVDGUq5djXP0+ZXLz28v7gd+hzIcKXbiCPiR2PxPM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a44e6e4-2e65-46c1-b627-08dc36f1816d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:47.0648 (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: D4SmK3ZXy7Oq0aPySvufqv6TU2EV6ayd41h2qd9RZZ+TNKlT8qRovi0xUTH5aL1gv0XvGcxFNaonMszS20XlLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-ORIG-GUID: M2Cwweb-YkKeXbNmzoNqo3abNzgu_Cr3 X-Proofpoint-GUID: M2Cwweb-YkKeXbNmzoNqo3abNzgu_Cr3 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 --- fs/stat.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/fs.h | 3 +++ include/linux/stat.h | 3 +++ include/uapi/linux/stat.h | 9 ++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/fs/stat.c b/fs/stat.c index 77cdc69eb422..83aaa555711d 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 @@ -658,6 +689,9 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer) tmp.stx_mnt_id = stat->mnt_id; tmp.stx_dio_mem_align = stat->dio_mem_align; tmp.stx_dio_offset_align = stat->dio_offset_align; + 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 95946a706f23..506c9230333f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3170,6 +3170,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 52150570d37a..2c5e2b8c6559 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -53,6 +53,9 @@ struct kstat { u32 dio_mem_align; u32 dio_offset_align; u64 change_cookie; + 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 2f2ee82d5517..e94418777172 100644 --- a/include/uapi/linux/stat.h +++ b/include/uapi/linux/stat.h @@ -127,7 +127,12 @@ struct statx { __u32 stx_dio_mem_align; /* Memory buffer alignment for direct I/O */ __u32 stx_dio_offset_align; /* File offset alignment for direct I/O */ /* 0xa0 */ - __u64 __spare3[12]; /* Spare space for future expansion */ + __u32 stx_atomic_write_unit_min; /* Min atomic write unit in bytes */ + __u32 stx_atomic_write_unit_max; /* Max atomic write unit in bytes */ + __u32 stx_atomic_write_segments_max; /* Max atomic write segment count */ + __u32 __spare1; + /* 0xb0 */ + __u64 __spare3[10]; /* Spare space for future expansion */ /* 0x100 */ }; @@ -155,6 +160,7 @@ struct statx { #define STATX_MNT_ID 0x00001000U /* Got stx_mnt_id */ #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_WRITE_ATOMIC 0x00008000U /* Want/got atomic_write_* fields */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ @@ -190,6 +196,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 Feb 26 17:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 776133 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 9C8D113247C; Mon, 26 Feb 2024 17:37:42 +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=1708969065; cv=fail; b=r8o70Yci7yl5P1l26drA94Tr3Wc7TQydSt3p+IDTHyk/Fev840kWrt2isfQfWPnCqlHX4ZS2896c4gDuEXjd2HOhNiAZFb+w5aD0NAzoq9Ynw2Jb0mw6cmHyRkN0AcpTiDkT8yR+FyzcMEi4I+qv9QGK6O5+jZURcTaqIXJMLDw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969065; c=relaxed/simple; bh=kWoLfB5p2KVwYd6PBvFkO+dbwwC8N014PUSCGUPq0AA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=MwGBmd3GbVzgzn4tcTdsF4KBODaUxcKnwGfBGRzxu11mmpq4Hc5AcHGKp/ADqvngAu78cpi21Bq838mirlCU+cg0y8BiZz4ixHMUh0KhPYaJlA14igrmKfe012YBsp1Eoc+qESZ9srQmXDIakYeD+ekzbeUxpZU3h5pFpQPb3wU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=Nm7LIt90; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=eA5K8uYL; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="Nm7LIt90"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="eA5K8uYL" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnPsD021398; Mon, 26 Feb 2024 17:36:52 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=4ZfGhdFSU+QwN07Y6UT2PnyEVbwomXG8FOr9tGvECgM=; b=Nm7LIt90vgT9nOy4UGRVOrDaPNntRylzyphOAmDTTYHd2uS6ReHG2zvonZ9vEh4oIuP2 XW1TzmNvPND7RQEeQtZmO1TmB2mjL0wPWUJkgRq1+aix+A+5aQpvqa6bTCWMD8gPMuRG aOA/V1SEhkxbzwZ9wIyrlGtzeu/KIuSKMUFUv+up5sGB1t2fmWuye+cX+Y90ajDlGnwh OtPClzwM5T0ebdO9yw6/p/Y+sVdtIO60drM+Qmjb8M6yfmK3w5KgBqhSRMljQpcuq/qm EREA8jKf57ihVAHisYx3rBq4Pr9VdvTAZoLS0WZoI/aYTzhY12JarnHRpxGbp02aqSXO hw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf722d65n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:52 +0000 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 41QHOTtY009826; Mon, 26 Feb 2024 17:36:51 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w5wa79-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X97hcc1Ps7aLHcSx4n7g5iCu048rRR5AJJ225VzZ4YnyyKfmNn0HZIKpfgrH53x46XA+GvImGTnkqiL14SgjzLBr/ZaI5HoufWBT4em+ibKQgn4NQLworPtX0yTgZ0cgKBnLF8wTENEKuLNadwEpwJ3t90ScM+HC1huk8UuY5MeiJ5Wg4euJZdl0FwXJKQAIHMW0zd2pU92mu//YA0N01KoAJ6yxk1ie/iQW/VH28IUoJC/stBz83sbLSOX1RZu2IqZkELv8wEVVJAj2Dr6RIUfM3q42Gkky30Lkk3w36GliEjP47RR7R1E7N2QATvRchggbY1np74MNubr7UbEH8g== 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=4ZfGhdFSU+QwN07Y6UT2PnyEVbwomXG8FOr9tGvECgM=; b=hOw8KnsdGSeIjPriaX6b6neHBInDTYvFofLHFG4Xq4uolU63nivtyvZ38ln/mNR/EIjdMp41DMcrmpWOEc7asYPctqgNCDh1aIze7bdXIP9ysCrdQ9fUfY3XaD+mbXkOawCcG4Y9EHbokmGeISTllRR2n3UYamzLcr56+UElSBw5zyU4FgsuskFm4Io0rK4Hh3wFs8CPNi7elMcPEsGXGP4faMyB+yMFy8smkSlLD7yCRPJxpX4N1k/B6MngideWxP2F+C9GkR/ddNWeWFsNZHZRoKDirT/8nH6oDZnlk5Uu57FzFVXbS7ymovmU1tLYLBMpixNyBnKWQiUStuKGIQ== 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=4ZfGhdFSU+QwN07Y6UT2PnyEVbwomXG8FOr9tGvECgM=; b=eA5K8uYLsn8N86KrQ3wJLvFSCP+z+o0xhnXlJSJcdWpkIGnvxmH02wqxsrUZASiQgbk3A61b0hyL1p9otIrydCIu55yzI0PQVvEdUdp/djJpaiClBxmv/MqcBYaDLIP5Y+a/i+ksWUKwe+z5O8cCn9tnTO+3qkFIE53TARVq7cg= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:49 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36:49 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, John Garry , Himanshu Madhani Subject: [PATCH v5 05/10] block: Add core atomic write support Date: Mon, 26 Feb 2024 17:36:07 +0000 Message-Id: <20240226173612.1478858-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH0PR07CA0040.namprd07.prod.outlook.com (2603:10b6:510:e::15) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d33334d-e4e6-407d-2d5d-08dc36f182bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TWcxpQAdCvPPhh4B+r7L1juY2DQJrbiC9d8VZe3eQ3XuTcirBKgaUnoktmAT5cI0VbbFaCmtpu9+cuNt+7n6iDvKxFh4YSWM3n6rH2m6OfV7qIAAAOMemVTMW/BgnoB7H8fbaXXxYjfPAWyc4d7YN2m6CIVk9fZqWHNhUGVIqkmwIlGourrKg/FyZHsBC4c58lM6BY3I5hipsjwkiB72lKGPePXzTxztBRcaPk35w811Mbk/78p2NaDfhlYvd/kk6YUOB9M6Z1WUcOINHWvg2sbzO+NMB8RlQFEnnmfnoIBEL2RBWg6FMKkoTgJigvWSf02686Ac6Oi8p3vk2rPSx0Ndjl8vzOHO12mLNxy3/X23GK0EEqZOeRPpIdoHnX91IT5tcAJaclDgm0dGDkORVwd8kdJNAss+0qHY06ITKaftyHOaGZvgr7YAy2ADKLHO+T8C/45NXfGi0XlHtCedvu/JJr2clMzXW70E9x3ckclqrS2mVujE9Rnhy1E7CqB2vL7gQNwlq9lhPoAVxXvlAzWOci1P6Ut67RjCXhT4XcktSIWpBbyvWeB09/V1SUrROjH+WVkqU8Zj5ukCMdfd6T5inj0vgLD9mWKhQ9TCWKtVV2wgX4dOl8ex+PC5spdlVtbAEa+Mi4jUa8pHo3c2gOOBM4z1K3AUfdutuCAIcoeVkaqKbsUQZyTMs/lfK0DUsXXf4AmNmONOsOCUbms1/w== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XQ6g+o3wVkKvSrdXP3JVYKx11hyz94iLCdMMOpSbZKOLxSiW8QBDhCSvsemci1Bz7DIri0Pyj/1QKHH5yVbJtKA7O0fx+yYT4C+aXOH+RWsYob2IZAMT17TQdziDlzdPH0yXBdtXZ61roQEGiRj++K2vveEW/zAmD9wLnwQOHDXfbiF9rZ+NbNPufG7pbz6O/9ZRoMHuLqiPk9ZRJm2k0sQEqCWOL3B1lgmUihecgd3JOAwQeHnW+tx2bHcADWTqKSpV+wqq8MinNNwdrfuIWYRQ3xXsvEIdKjLRFtxaB4VKLPESrrmaOnlIqJng9ez4av1qNBvlBOobiot5YJc8DyKwaC8i/8LLohtYs6gZKlV6JAXFH0bpaSfjQ36uTOUoPBCwxh3SXFk4m23d5+4uXSsy6ncgz9DGXXzhrhuY+sNX0iVvqQ6AhG7AtUAUHIrqXeBKh6pR/D0b4O3EU26YbE5zOjhZr0YPpd6vmb0kzh/WpObNK4KThgUp3WX7XeityovIxiY2cgYDRLz70zn2lQmjEMywn06LmQr+v0xEO/e5HQAEHjdvD8DQQiP5OC84N+TA4HIc5GZs48A8iZZJG7jskXsclSxyA28WuF8nzUbmpy+Jv9fY4l6hIQp6cVRq892OQHosWiB70QOLPtlHx6/V2QR1mOetSl5aqA7P58JpvOprqBU5s5I169ETA6MN1BVgYprGMCOS5o68/eB2nemNGQHDQzzKHiLGJARZ+8uY3wV/yL3fNoHhV5l6cMtUtnExWGnICZtNiEwjYsX7O9fwLvDujjPI8zfnmhgEG/gW1LcZ67EF6CF9mSs19KMLBruHytkT6dbAx6dDtuSZnXgooiP7QX8fEZkF+/88HVv4Rt9pqtkK/f59/+rJ6X8N1kAxkX4RQqmsw7/EbLypYtcqFRW/KX8WUPBlER47cyeFVW47JhcNi1a6tIdBijxfyuFqVfBtrPLFIrgdTfvHrHDSLbveSD0Q+OYfRE06HFKRvZV0zkZpq1bkzT5QJ8jEUWOCkwAaKVwMcxdNC4dwmR5fpdpntf5bx/j6H9ASttajcKtWgS8ldr5er7WndiYUNbcRPBkD3JldYBcoTekfzUFHr/V7GaIPn1iL2l6npZGX6bS/V7CHox3uDFjUHUJkk6LPnDla1myiV78J7mxw2gNOZ+LJByn7bosxo1GVFlg4p+u2ng8vcd+9UxT/2Q7j0hNZKhBLOXfiHFB8a17OrAXi78yaIIpLhW5VwXlHr3akw+0IdaqgGqW9FO2tev9AzA3L4vv6Rs43IYrMtubM5xxw8QkRshgtMhyW0eALZxNJYVHvn4bF9XTXeW2M118Q3HTNLf40/83Qz4T/VyR4Pv8pTUNYZKXSEyOUkRG0GItsLvLatZL8Jedw+OJwcCL6xpWu2BesMzCOSxevb48PUFBi7NwnaQCs1fXaS6Qqkop8BrFtM76OPGpQGO21Yp3RGAncfcq2CObYTTPNP/cwGPGPaHkegZzh2cvnk6pC9dz4duE7hL5rZbYHvKEGxsR6XpSY/keNTUMzvsqm77HDUexsyUTzqShfYuGXzmhmtkK+5r/eVQjgfFNt9vVMlewRWWj812PUJY+bS7PBRmRC7Q== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: zjJqaOPkGYoQ3A1l/kaQNgjtj6lUUW5vPHoMmsYsPsh6OK30Ak0kwPZCgCyFps8lm0MSaSBuaeEr1iQFpTcw+fFSwq5acgWrXca/tZ9+ntZ1MnI7aiToPixDiwtEqGbpfMirIa3A11kcGW/r5Qookm0e+IglJtwXSqiRMiXmY7v+DLMHKKXjoXVUxYMYRp/RCr8oWENC3aMyTYIuAdz/FCPN0aJkRqOO26KSF8ivc5s7g2qmLmk1l5IUj0kEFtPQmo+7GNCzrLJkWOQPt7rOCJth3IWB5eYKmtkpZYQ5QS5SyOsLh5Z+XuOe//sx0dyyyJ+laQdnqSSCcBzodhx+RML+JMDVztIW3/KU4QipnaHFVrZaSfkLYysm6/ULi4B9MvFw5HhW0sJM5RyDftTe//Up0wysizCy9dv79R1PBM6cCNeSd9ANCjNxrgH9DO1j6foNgc2LAO8JoGvkDJF9PZImjm5Em9/d+P899jGODhAsXepMmsJrMXzQwDbgvZdQwFbmyNPbSaPHMCNSwgIl8KPfrP6jIsiLxm9Hs7P+tphZcNR1JhNk8FZ+ZLRpqI1wD1pH4P3Jpz5oAJSEak9EmluGzdd3O7BTW5aX+uJTY8c= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d33334d-e4e6-407d-2d5d-08dc36f182bf X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:49.0398 (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: Uez65IleAmsxDvMsuz/S4Nh4Dj/F72sbEyTgr9GUgOF41RhBz9cOphKb79/Yzf6ZmNNaUnC1Q8x0Hc4t+WwGHA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-ORIG-GUID: sheCYFfU-Hf_noO8WVeE8mKEnmpUYQOA X-Proofpoint-GUID: sheCYFfU-Hf_noO8WVeE8mKEnmpUYQOA 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_sectors 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_max_sectors and the other atomic write limits. - atomic_write_hw_unit_{min,max}_sectors 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_sectors will be the same value as atomic_write_hw_max_sectors. - atomic_write_unit_{min,max}_sectors are derived from atomic_write_hw_unit_{min,max}_sectors, max_hw_sectors, and block core limits. Both min and max values must be a power-of-2. Typically a FS will use these values for reporting atomic write limits in statx. - atomic_write_hw_boundary_sectors 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}_sectors 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() - and thus we can rely on each segment containing PAGE_SIZE of data, apart from the first+last, which we can only rely on to contain logical block size of data as they are aligned according to direct IO alignment rules. 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. 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 | 52 ++++++++++++++ block/blk-merge.c | 95 ++++++++++++++++++++++++- block/blk-settings.c | 101 +++++++++++++++++++++++++++ block/blk-sysfs.c | 33 +++++++++ block/blk.h | 3 + include/linux/blk_types.h | 3 +- include/linux/blkdev.h | 61 ++++++++++++++++ 7 files changed, 346 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 1fe9a553c37b..4c775f4bdefe 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -21,6 +21,58 @@ 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 to 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 I/Os which + straddle a given logical block address boundary. In that + case a single atomic write operation will be processed as + one of more sub-operations which each complete atomically. + 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. + What: /sys/block//diskseq Date: February 2021 diff --git a/block/blk-merge.c b/block/blk-merge.c index 74e9e775f13d..60cec13f1137 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -18,6 +18,46 @@ #include "blk-rq-qos.h" #include "blk-throttle.h" +/* + * rq_straddles_atomic_write_boundary - check for boundary violation + * @rq: request to check + * @front: data size to be appended to front + * @back: data size to be appended to back + * + * Determine whether merging a request or bio into another request will result + * in a merged request which straddles an atomic write boundary. + * + * The value @front_adjust is the data which would be appended to the front of + * @rq, while the value @back_adjust is the data which would be appended to the + * back of @rq. Callers will typically only have either @front_adjust or + * @back_adjust as non-zero. + * + */ +static bool rq_straddles_atomic_write_boundary(struct request *rq, + unsigned int front_adjust, + unsigned int back_adjust) +{ + unsigned int boundary = queue_atomic_write_boundary_bytes(rq->q); + u64 mask, start_rq_pos, end_rq_pos; + + if (!boundary) + return false; + + start_rq_pos = blk_rq_pos(rq) << SECTOR_SHIFT; + end_rq_pos = start_rq_pos + blk_rq_bytes(rq) - 1; + + start_rq_pos -= front_adjust; + end_rq_pos += back_adjust; + + mask = ~(boundary - 1); + + /* Top bits are different, so crossed a boundary */ + if ((start_rq_pos & mask) != (end_rq_pos & mask)) + return true; + + return false; +} + static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv) { *bv = mp_bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); @@ -167,7 +207,16 @@ 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 max_sectors = lim->max_sectors, start, end; + unsigned max_sectors, start, end; + + /* + * We ignore lim->max_sectors for atomic writes simply because + * it may less than the bio size, which we cannot tolerate. + */ + if (bio->bi_opf & REQ_ATOMIC) + max_sectors = lim->atomic_write_max_sectors; + else + max_sectors = lim->max_sectors; if (lim->chunk_sectors) { max_sectors = min(max_sectors, @@ -305,6 +354,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_IOERR; + 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. @@ -645,6 +699,13 @@ int ll_back_merge_fn(struct request *req, struct bio *bio, unsigned int nr_segs) return 0; } + if (req->cmd_flags & REQ_ATOMIC) { + if (rq_straddles_atomic_write_boundary(req, + 0, bio->bi_iter.bi_size)) { + return 0; + } + } + return ll_new_hw_segment(req, bio, nr_segs); } @@ -664,6 +725,13 @@ static int ll_front_merge_fn(struct request *req, struct bio *bio, return 0; } + if (req->cmd_flags & REQ_ATOMIC) { + if (rq_straddles_atomic_write_boundary(req, + bio->bi_iter.bi_size, 0)) { + return 0; + } + } + return ll_new_hw_segment(req, bio, nr_segs); } @@ -700,6 +768,13 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req, blk_rq_get_max_sectors(req, blk_rq_pos(req))) return 0; + if (req->cmd_flags & REQ_ATOMIC) { + if (rq_straddles_atomic_write_boundary(req, + 0, blk_rq_bytes(next))) { + return 0; + } + } + total_phys_segments = req->nr_phys_segments + next->nr_phys_segments; if (total_phys_segments > blk_rq_get_max_segments(req)) return 0; @@ -795,6 +870,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. @@ -814,6 +901,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 @@ -941,6 +1031,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 06ea91e51b8b..a98a0c0eb4e3 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -59,6 +59,13 @@ void blk_set_default_limits(struct queue_limits *lim) lim->zoned = false; lim->zone_write_granularity = 0; lim->dma_alignment = 511; + lim->atomic_write_hw_max_sectors = 0; + lim->atomic_write_max_sectors = 0; + lim->atomic_write_hw_boundary_sectors = 0; + lim->atomic_write_hw_unit_min_sectors = 0; + lim->atomic_write_unit_min_sectors = 0; + lim->atomic_write_hw_unit_max_sectors = 0; + lim->atomic_write_unit_max_sectors = 0; } /** @@ -101,6 +108,43 @@ void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce bounce) } EXPORT_SYMBOL(blk_queue_bounce_limit); +/* + * Returns max guaranteed sectors which we can fit in a bio. For convenience of + * users, rounddown_pow_of_two() the return value. + * + * We always assume that we can fit in at least PAGE_SIZE in a segment, apart + * from first and last segments. + */ +static +unsigned int blk_queue_max_guaranteed_bio_sectors(struct queue_limits *limits, + struct request_queue *q) +{ + unsigned int max_segments = min(BIO_MAX_VECS, limits->max_segments); + unsigned int length; + + length = min(max_segments, 2) * queue_logical_block_size(q); + if (max_segments > 2) + length += (max_segments - 2) * PAGE_SIZE; + + return rounddown_pow_of_two(length >> SECTOR_SHIFT); +} + +static void blk_atomic_writes_update_limits(struct request_queue *q) +{ + struct queue_limits *limits = &q->limits; + unsigned int max_hw_sectors = + rounddown_pow_of_two(limits->max_hw_sectors); + unsigned int unit_limit = min(max_hw_sectors, + blk_queue_max_guaranteed_bio_sectors(limits, q)); + + limits->atomic_write_max_sectors = + min(limits->atomic_write_hw_max_sectors, max_hw_sectors); + limits->atomic_write_unit_min_sectors = + min(limits->atomic_write_hw_unit_min_sectors, unit_limit); + limits->atomic_write_unit_max_sectors = + min(limits->atomic_write_hw_unit_max_sectors, unit_limit); +} + /** * blk_queue_max_hw_sectors - set max sectors for a request for this queue * @q: the request queue for the device @@ -145,6 +189,8 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto limits->logical_block_size >> SECTOR_SHIFT); limits->max_sectors = max_sectors; + blk_atomic_writes_update_limits(q); + if (!q->disk) return; q->disk->bdi->io_pages = max_sectors >> (PAGE_SHIFT - 9); @@ -182,6 +228,61 @@ void blk_queue_max_discard_sectors(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_max_discard_sectors); +/** + * blk_queue_atomic_write_max_bytes - set max bytes supported by + * the device for atomic write operations. + * @q: the request queue for the device + * @bytes: maximum bytes supported + */ +void blk_queue_atomic_write_max_bytes(struct request_queue *q, + unsigned int bytes) +{ + q->limits.atomic_write_hw_max_sectors = bytes >> SECTOR_SHIFT; + blk_atomic_writes_update_limits(q); +} +EXPORT_SYMBOL(blk_queue_atomic_write_max_bytes); + +/** + * blk_queue_atomic_write_boundary_bytes - Device's logical block address space + * which an atomic write should not cross. + * @q: the request queue for the device + * @bytes: must be a power-of-two. + */ +void blk_queue_atomic_write_boundary_bytes(struct request_queue *q, + unsigned int bytes) +{ + q->limits.atomic_write_hw_boundary_sectors = bytes >> SECTOR_SHIFT; +} +EXPORT_SYMBOL(blk_queue_atomic_write_boundary_bytes); + +/** + * blk_queue_atomic_write_unit_min_sectors - smallest unit that can be written + * atomically to the device. + * @q: the request queue for the device + * @sectors: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_min_sectors(struct request_queue *q, + unsigned int sectors) +{ + q->limits.atomic_write_hw_unit_min_sectors = sectors; + blk_atomic_writes_update_limits(q); +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_min_sectors); + +/* + * blk_queue_atomic_write_unit_max_sectors - largest unit that can be written + * atomically to the device. + * @q: the request queue for the device + * @sectors: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_max_sectors(struct request_queue *q, + unsigned int sectors) +{ + q->limits.atomic_write_hw_unit_max_sectors = sectors; + blk_atomic_writes_update_limits(q); +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_max_sectors); + /** * blk_queue_max_secure_erase_sectors - set max sectors for a secure erase * @q: the request queue for the device diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 6b2429cad81a..3978f14f9769 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); @@ -502,6 +526,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"); @@ -629,6 +658,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 050696131329..6ba8333fcf26 100644 --- a/block/blk.h +++ b/block/blk.h @@ -178,6 +178,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 f288c94374b3..905c3dd53983 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -421,7 +421,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: */ @@ -453,6 +453,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 99e4f5e72213..dee88e27ad59 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -299,6 +299,15 @@ struct queue_limits { unsigned int discard_alignment; unsigned int zone_write_granularity; + /* atomic write limits */ + unsigned int atomic_write_hw_max_sectors; + unsigned int atomic_write_max_sectors; + unsigned int atomic_write_hw_boundary_sectors; + unsigned int atomic_write_hw_unit_min_sectors; + unsigned int atomic_write_unit_min_sectors; + unsigned int atomic_write_hw_unit_max_sectors; + unsigned int atomic_write_unit_max_sectors; + unsigned short max_segments; unsigned short max_integrity_segments; unsigned short max_discard_segments; @@ -885,6 +894,14 @@ void blk_queue_zone_write_granularity(struct request_queue *q, unsigned int size); extern void blk_queue_alignment_offset(struct request_queue *q, unsigned int alignment); +void blk_queue_atomic_write_max_bytes(struct request_queue *q, + unsigned int bytes); +void blk_queue_atomic_write_unit_max_sectors(struct request_queue *q, + unsigned int sectors); +void blk_queue_atomic_write_unit_min_sectors(struct request_queue *q, + unsigned int sectors); +void blk_queue_atomic_write_boundary_bytes(struct request_queue *q, + unsigned int bytes); void disk_update_readahead(struct gendisk *disk); extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); extern void blk_queue_io_min(struct request_queue *q, unsigned int min); @@ -1291,6 +1308,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_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_unit_min_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_min_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_boundary_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_hw_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)); @@ -1540,6 +1581,26 @@ 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_sectors) + return false; + + if (bdev_is_partition(bdev)) { + sector_t bd_start_sect = bdev->bd_start_sect; + unsigned int align = + max(limits->atomic_write_unit_min_sectors, + limits->atomic_write_hw_boundary_sectors); + if (!IS_ALIGNED(bd_start_sect, align)) + return false; + } + + return true; +} + #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } #endif /* _LINUX_BLKDEV_H */ From patchwork Mon Feb 26 17:36:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 777723 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 5FEC312E1DD; Mon, 26 Feb 2024 17:37:43 +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=1708969072; cv=fail; b=XeckrropkWR20u5hOfW/Jx6Hfn+6xWIQibRIwxRosGlkweDozOtLdo0bL++3wmHuSz8ZzIlgh9VYRuYIXipPUHUWHVyMJA+sRvaV6lSvOkf5vOfJ+FbkVjbMehyTX1RWBBW3wbKRNb/YMEIdSqn2TawFSUtn3E7KyhGjT1q5eaE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969072; c=relaxed/simple; bh=YE/LjT0Xd7gjGB/1Zuvyxakr4Z4mYKZi5JdVoHAl3oQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=GGTEyJUfYwKovExuTgt8gXEEZvip7L4v3FqRwdDdHxU7E3OsRvjLi1pki8xnkJr6ZMYS5vkOM5rngj2SJ9jIut1HP/f+dMSvmS7vtilvlqk+Vkv0Uqt5rROFv9Kz6F9/Gw8qVeK4K2n5UBnIFmWWWOvRbO6dFe8NG74DFy5B+88= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=OCQfSMJA; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=RTaM11Fm; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="OCQfSMJA"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="RTaM11Fm" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnLmX016088; Mon, 26 Feb 2024 17:36: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=RxTJeUuu1N/TIPajR55nn7e23m9c5xQj95jq67VyvpI=; b=OCQfSMJA7K8yywD6HGk9JNT/NSkQYKJL4T0oQXSFpp974e2bOO6EkOJGgBbYKH9RU7XF k8DkEcn74dldMgj71zBrRBT79x/wLjcJfxVhAMv0BlH300XxJxcImEZ2KZ1+PwoB63yX 5xagSYOlIjFhItBv+aGwpCF4bBvEvGNbSWQO2N6f0EuXqMeAfGW3urUw7ESXwYuMcIG3 StpZql/URmltIezPIKLcnskJOWlbs+R4WBddwUtgrMDhL+6wweKeUGFohC21AP1XsPa/ 8ClSdvBRjcmPQIWdXtQodJ7ePCCP9lnXYyI0qz4tdtX0XhVv04eSDg1DTd9Eq//HjPlX +Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf90v540h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:54 +0000 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 41QGjeVF022403; Mon, 26 Feb 2024 17:36:53 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2040.outbound.protection.outlook.com [104.47.66.40]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w61thw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hTPkT48euYyCzEyszjEI5JqFqpAYyzKp4qipU0jVn8VQ0X2alD7HbdxfMrsdf2/Sp5btb/itmKC1a3qzEjAvSBUD66j7038EF6BnvypN5GhlwA/l4Ersdffu4LnNS7LM93C4mLY4SOSsHQN97kRPstwzXgHghML2phu9uYS8lfvz9eYSs8dMsXdFG9NOyiF7/++L9yweNjLqa2xXV5FoHP+0yf8VXbcoOXD4vCjmc6gezrC+sUNPaB/pvkMTK8f4w0G8be8iXrVCLRmDrwMqCAH2qw7F8BUFwQrsIZWMR2QDfp/BC9ghGgCV8wEl/LemO/EYhWNhlLGd6DOJzV3Fyg== 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=RxTJeUuu1N/TIPajR55nn7e23m9c5xQj95jq67VyvpI=; b=EWW7kk6chMI1oNo4MPP+Rp4LYq3r6Gh+Rnfbo3q4xgyGcN8Dwl+UAdvBJPvrAUScDq0ny5IMDc5VtLFrfGtx8ZhgVr40gMO9wIoe6aUrX+MoubwF6gxtPqGxikk1lgwycUo2fqDeqA2hMHamD8Y448KlrtGBKbrMHNGEmGy2Pg3FzP+dEMHagjA7cCu6fgtZIXL+jH7YwDIcBITK/sx/XgNEXxEVMXR5douAwNpS54TpiDuniYVxR0w3HVU5Z2toHHrTVBFeTq+k1tU+7V9P1jmMMPOxAwbeE/9Nwg6hry2JyKIPoCKUYBYU2/ClcdnJLH/WALpzrfa8eL1sLWwzVw== 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=RxTJeUuu1N/TIPajR55nn7e23m9c5xQj95jq67VyvpI=; b=RTaM11Fmy9mCXqLTCCM8DXEp7GMjkR1mjxnawxvwkYQRPDVnu3zdffoQk14RG9hHTC3hqs+yFLAYAqyFy0nJyJHatU1LjIe1cmUm/nGNJdgMfgd7TEaoLmKkb8rGRVVqVMiGwNt2HTTFR3ydYHwlJakD7JP9fHRTMBmlKPB45QI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:51 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36: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, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, Prasad Singamsetty , John Garry Subject: [PATCH v5 06/10] block: Add atomic write support for statx Date: Mon, 26 Feb 2024 17:36:08 +0000 Message-Id: <20240226173612.1478858-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH0PR07CA0032.namprd07.prod.outlook.com (2603:10b6:510:e::7) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: 201fc476-6276-4e4b-b404-08dc36f18401 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 64T6DozHSYpgOjPv3rp7o72zSHg5icpX38M+Sq52Gctfy1eQJzL8IXpwdF9FcFsXhvPf1RLkYnJKB8nCHiYDGsaCJu0eaPJjTXzsfC9hYmoq76HbqXSBcsgTqn3V2bh9zGnLP4HnazLvRF2riQdet0yugAKiskFO4Q74c/ErOMDwBegP1T1X9A5GSib/0Hmuu8+ShskMKaITaotpG9CLAtpwpDoOdz/cJoMQ4oABxjnxryH84PkvnALeeRbR8KspW0Y94vM2iPywqmE3UcZyrAqS3AwToNFm/mImC/lTeAkGY27nohCPGBOl0qdurUbdlRz09XhHtQlbB/4rtTBLEK4qFYal0NHyOZzO9BjXUjQFN6u9eJ6/PcAjH4G7lC+ct3lW/O/ox8DjTPdhVLzESqqyG/Lk2fy3Z1lfj8G/go0cJe59oa1DD4Z4cEBPsrjRI0lN83qGo8+IgkfNRGB2BNyNoMH4izCxT5k2AnoU4lgU27c9vKJEsGu6T6mzKylAmgfFOnGQFN6v/DNlrUbZ9qMyxCQ2zmyGWAp9zwrZXRCzcVFI8X/zipntKMnNg3GSSYcSSqQA2/qOMuFzXFLAD5GGgO9DSM1PYxw2JGXRK9TBUKlQCwtMPJ+zalBN8Qu1Ux6TswK8Hc9bncFLy65x8S+D29VVaxBM4HNTTi0SRNIeFKrGbmLE5DK3XJExpEpQwX0/ZRec+69/4ohU0Sz11w== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +TM/THG3yJ6h93JvLQRo9Qhh8EZM001ZGlaFxsFA6UFG5tLvC1Jl62AP4LGf5bUEJHGZFiVJV4WVofBjwwToIqscLsDC92pPEhj6Fb3Vwy0Jiza9IADLz2vcpwiwD/dWTYttLJQ867doChXJv4QrZHuVvhVs8jGtkMQsDFPmBTSjXUEHGEM62L0suRD7kEBrFFcbloOHfaLmH3pUYAzBaw/8yeosjzKBI4cNGOM2MBqZ5hSPe0uiBk+6TiS2x/J/MWPcVIYBRqRpnsUfWcGajEogY9VkzJew4r4/UszrsbwUKfy2alJimacxQ9xlodeXB/FmJ0/jKN6r7i7enPTcAoCawARtnN/moeZHGTMIxLgO+/UxgHGJ8s0Uj9omrowZ51SKieS7TlLfHQwiz7bmyvZMrgVUTtnNALUB5lkTnlMNx6RRf5MW0Qzj5QuH7ZkIbBf6DdvbMqS0TShz2mVUAyc3gTgWBsfA9loMg34zDh+GaUpZz/B4oF1YdMgLTkoONOB1zUcP3iSndLAJTPeQolXhsYQXgnd4IQpBetCROAy7bVSG4pH/25gGKNdGhSgnwGG0GsMxWKXqQ+7WF0NdgLd+qoXKIetMVwHsMU/pV2Jl5qfd1PeO305VeoIDvlc1wSSbbF5Y7j7bUxWBxkQ0VtAldRbGQBE9Yu6Xn/LGEcs7YpVSm0886hZurc9IqYxx7dx27pNBqICxQQj/acwV+KbQiNJpb8jLaMAfS67SQ4VsQ9D6UZB8vpWRtHPYdmeNI4GLIwRKcmmyAxiBd962mQo+a5QmrpnsJQ0fbnfD9Oyg8P4ojkE7i+hFdFfH7STgUGaUNHhTkbblDIcwMTZPNm+1+quXLyfnvWW2pNFS6A8wjh2ZT0vO47waOK/onzkUUdr5NpinsOOItDYfCZwrwKxXcHrU/M+NCWYlgrYcvKS3YjfHjGMZQIjh4PayygvFtD+Ia6ndPqovQmuqmYMUYqWE398d770agfrlLOhuNhFrdYkCCC8eYut0vCgUdreWSMFteBczg/dIVCu/7TKj9RnM3/Iafwpg3XeKznNzg2PeerJO+jaDPUVT55V1Ph7WfvrCjkRT824EtgWy6TUS4aWALwO8XUE7NZ7ZDOst0z7cvqgjw9vYmnUnnrl/We9fuDLp0zYeAjKzucWrW632rvKjlhlBhDhSWmxa/kzEOC8pznjUBVUWY66b/ogYAqz54zymV8U7MtdIM8QOE7lAgmBX1maCxzdS2VivawStd+gfjeSCrB7kjse9kgMwgjTrJXeo2Cluu/aN84U9yb9CsFoSjh9HRqivMzpPaglM5G1SH7jtEYtXSGWttV+fzcLPppHgsbAw+aiQ6EZMC+no7enhExYy0bX1NGzyW2fodMLlRM1Nng1qY9q69T3aXrwqGZy/7gwAztifKlV4tPLY6sH1pdm/jshW1J13O12dtagNf2qg0No1DI/XsiqSnzF1fzhv3PNNyUwI2mhRuY0xZlUH6Y0KolXbvCulwHrcHeKm03TleDTaw2XEwbxADMvHfyOGFORwF8jHIqg0WudaofIliITAZkRWs4sqC5vvPkel8RXfKRAttHc6ZVQzH99C4nSuDpJoXOl5LN8/1MXXJw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ghVj9UEFSkPcSS0znC/GTbd0wKgly9MVy7QyI0uXduplmTE66bwCfO6epcAIE29RU7pvWMfzfi7HI8vKKlv0PQ6+xowSKQnS/OcYrJGV9Rv/hRI6WjR8MwdWD1+gIiDgvBxXv2+nJZxzT47PO3hr1QBADQDb5FDXWcOxxt1tO++aSd5hYGbe+a2T56h3PXLz5PeHTAs4iXJtjt63M3vhFETPjOlytNwE0KY2O6kfoBGVI694vDWVaffrgnL40O9t5fOUOZGNyax+L3qDaqODc8J+ryqxka2XO42iWO5+VprCh5iJb9rxINT47kt/jAQwZkZ/2qRsA0q0nE52HUQuEtNgc3PZBsIrY8X4RoHv0cC6b6JlTZAcx3uxK/w1EeskQDBTjTRxcyR3Ypvh6B3jIPe3f0oHUsYjKObfymiFif+JS+2nD30AAru12eSsPph4ir1LgVCxDR6deXIuuA2octWcu5EE2RMhjhphWCG2rjAKKhfbki4YhUlgqqe0vtdNRe/vkKs4kVHyZQkoulF5EWGy+ccyOZa0XHLU7nohlAYH/VZVdO6XQO809hKifDJ6lUhjaWj6AdloUN0RMsBa4sqlJar7hsVm3ovqBLXLoz0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 201fc476-6276-4e4b-b404-08dc36f18401 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:51.0780 (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: CBAevY9y3iNPxmzsjPE794FUpkrSI8MrDcM5W9lkr5LpW3gSDZhQS3VyJVlWZjt3zoHmhzt0wVBp2PnriewA0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-GUID: -SZ7PoMCFaAGtIfoNLTgRdJD7OtHA1c3 X-Proofpoint-ORIG-GUID: -SZ7PoMCFaAGtIfoNLTgRdJD7OtHA1c3 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 e9f1b12bd75c..bd23f10a425a 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1117,23 +1117,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 83aaa555711d..0e296925a56b 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 dee88e27ad59..40b40e49b244 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1542,7 +1542,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 @@ -1560,7 +1561,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 Feb 26 17:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 777726 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 6FEB3130AFE; Mon, 26 Feb 2024 17:37:30 +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=1708969054; cv=fail; b=kK8gXfkzYseAkLtkuG6RXQ8Z8AV25LWpjYSq/DnXnWF5irMgM/Oa2P8zVBCxdv0XOiRkl5MZ7dyMDg+baauJCPGvVN+w8O1MiKFzbJlb4ryyuxk91Eon4YiYHi4f1nGsggapPxzTcGCp0+3gruRO0V51wVrXDjZ31fffQBsxuRg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969054; c=relaxed/simple; bh=r2t2Gb6tJ2UpHpS4SYaN/zyB1MOBuV5X4cuCULJ+l5w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Sf3Dofku6y54QaVRIYBfJlet6gb2bfT9EMGgjtmSUnBSuqVxpS+lrTtuGhI8bV3I92SjT1wlR+FsDs9hdVm7MSC3N0pKvgzVPTf68OWpEALJTxAce1tbWakkhIQaOEOm67JLPaWf8YDD1CTZ2+C0bXYucFwhW3scUCk0l/0GIiw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=OWIf7qT/; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=tEbS+H66; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="OWIf7qT/"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="tEbS+H66" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnHKr018491; Mon, 26 Feb 2024 17:36: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=zqCzZ+1bbnc9VZ0wr101aGS3Ip3L/kml2Yi4LZB2clQ=; b=OWIf7qT/Bj7Y8SkNsEqdaBcJ8ncSsFEl6S7HP0lXm+i+/jI+kh0CygzahjiM5Je21RFu XqiqiWDe6ZUS37sooep8ft9guePDLb9RdAW6GNAMShsZAyvrbVt1WhMpiqL3FBqoIL34 fGGEYtZK3GidjSaipfOI9Hwno8gaUt3hzp5c+JHbFO8kag9FmvAMYCLGDZUWfCmVYUmk aa8EScBWlxlKBcfUVSQOQNL44C+/P6F4fzWGYSkWuWrf2GuD7YQieE+WnkXeJJBXJzUJ DpipU8R1B86ePaLp+MMA3wAoRxs1eUFovKnzBX0AjDIa8p+P91P3LKeo+THZ9o5/XwDW og== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf8bb52fd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:56 +0000 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 41QHHY5X009853; Mon, 26 Feb 2024 17:36:56 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w5wacj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iwZW3c/AJpwjhWy+z4/C75vWvTJrPThuSCKDYvRR9Qddj0BXEFlXUzd3r5QH4HnB6F2zcltURPXKY9NpIbJf8KdJT+NPcJIBQjiykSUm6+nUo+ukFLxEKog2Fen0r7Zt2I8Y03SYgJwvVATBWXASaKNqVmoPVP07sFunlvEg0grpbBgdL1s+ytFmUj9HI0eHRT4EtmbBomceWnfA1n6ffwirXQXMi2juyZGLNnVn91MSZstfnVZUWIXOKfHlxfovgX1aUfnrt8bU0J6kMN3W1d18aYVPJ7cerj6p1FkG8q0ZPZcpTUajG35owJEfjzyNvlRz/biwtliy2ZM6i5bMPA== 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=zqCzZ+1bbnc9VZ0wr101aGS3Ip3L/kml2Yi4LZB2clQ=; b=TM7KQYKoxDqQRXkeSX3UZg9D4P5UXI7hTtxAAaU8gFjBewUpsKiVJOSZo0E1cgEL/N9O9Iv963RIYLreG318NmQrtuaSkV4NoRdln5DjGTQksGjmGp5b+lCGaHC2UnAwTp0FCkPOtPG7g6LwzZaNmapg11yafUCaU85avwzL4xKz8bvnXjbvwCZGUgnCDkc4oQ2PdSbNEusPctn9UGHhNIbEC8ePq5xcz6Mk51IKxrf+6BUXqTyNmaZTi0DFp9fjslzZ13Jzlpiu+dLXnUpBRNO885nmGblV0eIQw5p00By95DYJXFlCJA+uHGr1aihxQhQqqs5dfNjfIsrXiiP6og== 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=zqCzZ+1bbnc9VZ0wr101aGS3Ip3L/kml2Yi4LZB2clQ=; b=tEbS+H66agjzYVzpND7YdMCZoJB39PQgy+db9zKpjD6CujQLJ2zcm8BM/O3tdZlJPn61ExnGNQ9kgL4X3nmv/oO/Gb0axkiLo25hEL27ZQ5gwdRkvQbkGppfdxXczUknxv68YDKAlFI4AVqVx1w/b30OsvkeyOzwsjZYxsqTq0I= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:53 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36: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, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, John Garry Subject: [PATCH v5 07/10] block: Add fops atomic write support Date: Mon, 26 Feb 2024 17:36:09 +0000 Message-Id: <20240226173612.1478858-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH7PR10CA0003.namprd10.prod.outlook.com (2603:10b6:510:23d::24) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: b386c6c3-3a08-4d2e-f100-08dc36f18599 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Pdpw0XW0PaRRe5A3bUquw/VXLvmMKpWTGuu8wzdf3Ahmrod1vFq6uiNDB/r+KomSudDy95RRaSvauG07ojCQv4y2i1rsFdRI592csJH8dJa+IIZCkhTffuUnwqvMQ6cqJnHN+NEcAZli7Lafh4GV8O1rGAWE7TiPPRKDTfJ82O/MKs9UbiTgFVf0d0giYcUMqZn9TINTdS4mq0gsq7G+tAAuXTFpVnW0fTh6bspbiYYVUBJnUDBvZFFxvFDxi5zZMu1gUVfZgTLVzr0FWq5NDFDiRUaufoJkHe2hJKSnmWvMdln7uVquF8FIYFKMxcDw5a92pyKtYtW8Xq2FBRHUEAG/8vk6TSMnKM662JVj0HyE2JJea0/YNIFxYt3PmrN6DnbeA8BVPNXJJ8NHXBbM8kGyx8yprmwS9gJyLifyrI3H6IIYmxAFiuhePLHgeShQmle99Txe/vIP4M/Kn8MT+CFNDjzXxdrKEiymljkQGg303Wz/Kjy4gQ7pL0dhdvgaa+zJ9JD5U1QVBOSgpwZTFRhnM6cOYVTKnI1dVtCBAHigOjsIj5YRMWJpviqXsAkaDzOnACY0puPkAsVoJns5MlXjdMz1u3f0wCPobKcYulH+xQZpu6EcC67sLVtn8/ZlFewqR/RknKw82V4CnOkxYXz2g4SV6cb2q4gXyKx8lGpYFydLCOLZqg37v0bwL9ZYeMsCmO9onK0jzgIqSjk44Q== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G6Bckomjl1VSue9K58ds8UDuGDUGerJu0Cm7KsEhtTZfakXSoUU0ljymPyAo4y0yaphY2yfN+a9inTdgbdsFQqhnR0EknkoLO02LWt4C3yVA2vF9dXeCq19lKCDQ6Ucr0iHWawLxIuyx+gnz5eaGVzs9YGuhyRKMEOW/8hzd253URDGvRpFNoFYTG+fOuNavlJDj/YRab6baCY2VBbWBIEOb1AP81jkm16tRxN5sopRSEez263b6ihWLIsZbWgpK0RFLT+ARQvdCcWM1z+qC9RsuCJQFlRe/iRyFHuOpP9Xdv7rIacq5EpQvUK3ocX14Tire/6uRWhpXzuMcHKPCa0SG6Gej0hb4XKGMPuLq/E5bJ/ejP11CWoK1G3/yEtaBUB7IhIu3CHgIUp25df+PzbAlJAko7P12OQ7ZsbyFAChnGbyoyAZR1o0dmVTIdkJsaUUfHaJo29ojZ5/jXoGEYS+gSObum6IfbWEom9qVajFtE+m06jvHIUj35+ixS7dcQlVp14RFCv0zhxMR9Un2IsKXmO11moOBPfBNo7ab/2llM2OnFo5fWmULNmRcfhP1yZeabiwel5xozCAoYGdy3iM4XKufLKyftRBOj4Vz9Me1Ffb+KtnmnljEnEoFTLreNPTr3vKpIHz4vq4HA/bD+Y/fSD/PINMbvkhYQC8Kir5K3PF0S+AcamfNfosL3FoF79O3D1J7qLArNQuXUMkiO37C+9K49XeLdklJdrYhEHuokYsHDzq0LYV2e2/axN1bSCroEVKKCfgG8qGlXrebmzhXn0Hl3LEZTIXmq1sNnrXLd1WVmOSzg1VdNvjVCmUshF7tBl5G4CGvuIkhwD15BsoqxPJrcd4vCm/7Ss4ELcBIzBgxrnAvYoEYt7+ak7Dbej0wyWIisDpDVepfAHgJOGw6Bgg+2Yun4Cdl9bJYII3mblQX4yGjtrBXMY09BLYMeYwMq8LEgnBSbnPYbG6kvaltTQe34sIy5aH4SAvyM70Mt/14nNl+0WUthVe5owKPuxpid8s+/vvir+DwV9F8tavYej1X0hlvu6n3FjOR54WaUUGGwyYQTUFKzlJetdwqALmJb8BBNxR3PJlthLxFnqWNFUfP8r65ELKC8Foe6Jo00AUk88ibHez8hX851m+kidSFuqFoCYkhxrOGdz5ddNYvLDaPe9mNzU7eOhTqaXilmQzkHlZboehM3Dl/wFSauukyWmJdpJT7bwP3qe6TZOtXJbFzArYmOnBJjVWmZBMPrnLcBdDAbtt9zq51Z1k85oHyAXsjfdd20h4/OR5ww/n3MAXpnkZApY9HaZHN+r1buLOOXaffSan9xSopRA6X/cUzAUKzXn61dnz6593YQhmM/v9gr7IiD1VjwvBlsEPSdT4emDjeY/nD7MBWuU8AbcY5pgEqmmiCS1zto6+gpjvnI+gl6PDEN23D2x12dOMoaUe4/gisLBWBmib3yA495i5RdQZTDHR5hwY7Lszj20gD8ZJdPqNxFGMzLyn8OYhONsTvgVWtL5W8X+dMYwLGirsc1BdijNPwRWF8jsLBXDCDBQdluq/nkC5KfdPfQP45rVM4C/BUg/MgoRt+3zn7jP5mmQpvbovQTn3uD05s9w== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 5QMyxsdah2A8w2XSw4K5BOjIVi9nckHxGC0hv+C6++DucAJUYB9Kn9GOiAf6UYDOzKQ7I8N+SiP4yG8/6DNEIP11LE7J4gaGZvCXL7d6eVWwSCsQFReyg6pk5dieI8JHZb26czBH7GiiKc8ltS1xmGBSWKcOPNBzN/C0KIHUTYt84ESvwZISp9hfLUYgBShYz8WuCEFyJVQiy8XOSohsgP8jBwvDJewM4vTS0RmyGN4VMjwhXlKn11cWDHPqDHyzTVnQahfSn0dWfFePCeIHFGZ6YaPYlNAq+ZGur+DgCUPWQeKLCVIv77koDZXAbmkMw0EPX7DQmoiyFdBCrBs0BIs2rJnQ0L9AyV3fBLdXFlmemfkrIkpnwbtYMrUDgdg6PWwaywqo5tzw0j6qooXUVi5Swr+gk3YBe8lyJS1fh1CX9brwGLvgHBi5G+cit7aXCEJvN3lPeIyPoJ5Z1ZdUlHc+CrhWnkoYfb3nsz5V45e3RucTaaEQ9WVTioGYXfQL2A6SzzxZXIgpsju6utjyylfFqQ9uJ2fkn8lY1onCHUEvAXp6V2pB+oihcdQ0MpkaiMdJfZZS6QG18w1ut8jf/SyBeO0VBGl9yQjze9gu6AY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b386c6c3-3a08-4d2e-f100-08dc36f18599 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:53.7584 (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: cRk86lElwN+8uUtT/tmWJQsEw7SnAzMEaYcs3BCtkDdtEE5V6zf7QRsnR3+PjENKbe6OgbbPhZiBguobJOR6ug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-GUID: IPQHUXO9G5UNkW2KRXn3jgxV-Jw6EgWG X-Proofpoint-ORIG-GUID: IPQHUXO9G5UNkW2KRXn3jgxV-Jw6EgWG 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. 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 | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/block/fops.c b/block/fops.c index 42955b6a1f5e..3f61b00994d3 100644 --- a/block/fops.c +++ b/block/fops.c @@ -34,9 +34,22 @@ 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_atomic_write_valid(struct block_device *bdev, loff_t pos, + struct iov_iter *iter) { + struct request_queue *q = bdev_get_queue(bdev); + unsigned int min_bytes = queue_atomic_write_unit_min_bytes(q); + unsigned int max_bytes = queue_atomic_write_unit_max_bytes(q); + + return generic_atomic_write_valid(pos, iter, min_bytes, max_bytes); +} + +static bool blkdev_dio_invalid(struct block_device *bdev, loff_t pos, + struct iov_iter *iter, bool is_atomic) +{ + if (is_atomic && !blkdev_atomic_write_valid(bdev, pos, iter)) + return true; + return pos & (bdev_logical_block_size(bdev) - 1) || !bdev_iter_is_aligned(bdev, iter); } @@ -71,6 +84,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; 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)) @@ -340,6 +355,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; @@ -356,12 +374,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); @@ -370,6 +389,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)); } @@ -615,6 +636,9 @@ static int blkdev_open(struct inode *inode, struct file *filp) if (bdev_nowait(handle->bdev)) filp->f_mode |= FMODE_NOWAIT; + if (bdev_can_atomic_write(handle->bdev) && filp->f_flags & O_DIRECT) + filp->f_mode |= FMODE_CAN_ATOMIC_WRITE; + filp->f_mapping = handle->bdev->bd_inode->i_mapping; filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); filp->private_data = handle; From patchwork Mon Feb 26 17:36:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 777725 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 41AE0131E27; Mon, 26 Feb 2024 17:37:37 +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=1708969062; cv=fail; b=OPoMlnBsKj2vaw4J1/hz6uzukQRsnFzXAaBvrCmGnzYMu1/e7PXl30+yCKPoIdoXhkqrSgZVPBffdky2Xn9b3gP6XtglKBpXPuHHVwa46hIpd5+exMi5kafzF5Gzb/31apOOjBkd0w9Z13rJdNqpBtjfHucPhkKAVCZg3vMHSwk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969062; c=relaxed/simple; bh=odZlsa/cx2ncQ/+LrbueYmXjt6zmVVz7xjnIBIcC384=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=hYFgyWjQxJR3wqx9X1Jy4qb+v+aML7LNLjA8F4aM8dSE+84nBsX5dNnBulLOr/87tV5GKNT/UaNdXf+iioVBmjfOiksGkJwpK2kzCxZO4clAbQERiFs6ghAhDEXfbnHKPo1CY7miffn8j7eP+jHRLsX1bAiHy/5rhJioIyd40Hg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=m0ZeUM4k; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=bgt2peXC; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="m0ZeUM4k"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="bgt2peXC" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnPQP021404; Mon, 26 Feb 2024 17:37: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=DIdDKea3cdStt5bdShr2QzUfCq9xDEYo8CdFe8lEs7M=; b=m0ZeUM4kjR5/i+KWnNDBCa3yXKjsj62/ElbTUrFE6b+VHXM7akmC+GAkE1B3Oqfw7EHU 54kSDnRC4smvWRXoYcn2jCg6efE0KjZ7ImbeQ+qPu29ULUKFTY/JLS+p/yu7eLD+2I6r kBEVg9IX6kjEUQUokPhKcq3/i5rOOFkcolwrIzZpBibTz9V6qHVQ0Eo+kgzotcpxGTtS r3JOBIAQKkf6xqVVsYpmB0yjMJ7tR8AE1bwplpiPVkvpjjR1IO4SQ8Jt3WErFYP+VmUT SOrJGdZsn/Mr5pXASZ37/QQhzZcSxVR8Mbb/G4vkJNiZ3S69OB3InDfE5SUMhBfX4cT5 hA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf722d664-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:59 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 41QHKxUB015331; Mon, 26 Feb 2024 17:36:58 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w64um4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:36:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FldQrySl+1bHUGEe17UGdV3iG7bWFRuh5uhOJnNDcLxBN8so6El8/tV4YXdd+ocKuWrCnYGd7Jbk8hOZETrh57pIbjJpj1OKbuyBPYjVYIG9Cj0qDK4h+v+yC5A2zE+DKQcupDxDptFZn5Apefv48R+oXA9j1l3AaJlQZa8J8AafTEt7ckpU2wH3KwFKMKO7t9qswnR4zzWwPteAdwqr/xLW23nIz9v7oBCLWypAGJ4ayNsoPOWLHEFNO3SnSoYnAJfAY6m5qeIAfZumU+5ttOCYttggOuxjqOROX8Rrx+i+uQmyUyvwye0QsTp8pitlFd80FBsGJdKKowxx0yPNNQ== 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=DIdDKea3cdStt5bdShr2QzUfCq9xDEYo8CdFe8lEs7M=; b=hGFk/xA05hKW6gjSumK7dSCQE/akK3xyAgqMpoEzPqkpnLtbX5cwzmPwAPSS30pML/E56pKmkbARr4ITq3VQaLLHpnF1hTmPYdi/DaxplEO1dwxuGgFjcpOOJoGKJYBmI5s5C8bw8FVp82/H0gQ3DNOxD/eanxSZwewF3cYHpGQmFfsLruyJ191N7EEJcjVdbv29IMeiOwsZVaEc9gR50NOe9ih6t9Sc1PT4OmDzaNgkeBpoWsjs7Lk7OBW98ih9umywtVzBmKFf970Rt6vTgUQz5BxsmRhzsu9dNwO090FMuO56f0dIjJ6XtXrNlnYW+Mj8egjhvZuMMK+aFTbmuw== 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=DIdDKea3cdStt5bdShr2QzUfCq9xDEYo8CdFe8lEs7M=; b=bgt2peXCrhImba7nR3qIibxzRs3RnK80MeAi2lgH3Ej8L2y4Xk4Xhhst9lzof9jGAb5DeC4p4QvJKkWaOX37mrbwCDmii7+ZtDTBgDDeoFrWV/Gz97svMl/T5Z6hbnODstl31IJyYQ8Htiigm8zDjpSCauGBB1HYJKBW/ZknK1I= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:55 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36:55 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, John Garry Subject: [PATCH v5 08/10] scsi: sd: Atomic write support Date: Mon, 26 Feb 2024 17:36:10 +0000 Message-Id: <20240226173612.1478858-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH8PR07CA0015.namprd07.prod.outlook.com (2603:10b6:510:2cd::20) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: d5b462ac-2ad7-4694-3ed0-08dc36f186c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8N+BYY6bllzBxsjNfIglyjunELJnZuxU114Mt8Y8NuvYOR1VxWfBWEzSYInZeFEtWv04U18ez8sGkowC+B36zf4CsBiTlTVH9pW3bPMBevIy03b5b+5iYla/lT4Q1ePZ0Bc1l12D81/znluXAWHozxO4CUiDh3QyfOBblMdwfWcR2AmrZeVyw8ZjTkKdn56OyuO9UsqagKLVyQO8EUdLgQhCppEgX1B69i3qK+fQjSUB2FBY5OS8cCmjlEr/vujgkds30l7Ny6VvcsYpqc0VkmOI958acYGsu1M4KwrRFpiSzldqezBVey0pNTwWYckuK54r+D+lYk7u870ADiQLh6WutHNIYm02GveUMcS6jAsCFOscy9pxTG6sj9MPYGk/yIRUYCsfDegSd4k/7QYK7gy5qbbLSOfMHBuxkwjHTntIIu6RtWgjJzIBvEilnZTe1CmpoU1EoI8/46/YIxMW67tUmnGmVrJvWjMyFfmQyDhyNoKeqfiZyL5kd/JDhgVrLmgX11S43KNh5QWEwaF75RtCR8hxalcTOPQVnZlbYL+Q3MzUg12DgT8Uq39lYh1wWZluRIvHU87KxXsGrfIm5RYKK8+pvOpHn29snJT9ygDdlOzdP6PpNRyjwafqgjal8eWgzfpq8bsztI/qMXg0rcJv5bCvkNpsVcJ5rSSUSr1vPFdP/vbetTj/VUPaQtEjEAP3vTj9p8nALUKkzEU+xg== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 76U7p/kI04BOixMbv9YNNarnKYgCaEIutF1rqeyzrP9dY6fjyEt7Q/xlycnPx1ZI4CApLu4saplO8gvo1YZBUqIA7NPCnXR+TTdHiAD7waE7dj86EPUfmBVxkKiTkvc1fguKrKCHKGVle4ELsc7herSy0Y2ADRM7+qSlz1vDNHUDc87OrwxYgfxMVCEOknfzVaL6FlMXwUwgIprspu7iE7UWADKxLIhI2y0EeQ9PWIgnhWn66Y+SV+35BOqI1xnOWH9ogN28YBsl4hLvxWzNBMTeHS3QPBRDbUR8jBM2/5woIr5Pi3E6mE10GaMit2U7BP/B1X7FvVI6Mu9AJat1W0IQMd+TWnjb1gmtJV4nqxivVqxcEeca4Kujst9VFLBHJM84JMMaE6BQGZZVpdsNPYDxejI9mTjOPf+grIeGJcM3Nb2BFpAcRAY1USk6xuTGqplrgk06GU5G7u496huoYU8GlRzmYUtom6/Tk8M8K8HtQpfFn/x+8++xPBl4Z776fM+JH4CZ+2HeGxIs+CUXNKoNum5lvehOXLjbYO94LqjJO/0cxeAu/YkPnas1DxPQ998c7OQFEDcZGbTVGu8UPM8tay9G4VM9HwbMdcopi05at1B6nt9lurPAb2w8GXDyweHvOugXQx5QuIB0c3/ohfwSaF/rispiYzAMCqDlGFYVy5oXnFZBr5KidyjQDyNAgNp6h2vmz/+haRGdMCb34XjVilUQV9q+nNJYNqsCndaw7zBuRn+EyEqRSz20DWAuFWcFED0kVNhr1KHpZ3EDgwuf2HtxafH3C+vn7L1y0Ymx6+mYzKJYfqdSOAmSAS1K0H3ppzn71m9CynJOpaP2740/LhUjKVrDmS0Rw+rUMhTGIvEA3GL6hUPZPN9jXMSJs1misqJZlJkWSOb6+93ePFdHiXGv3zn5HLwfCeczr/Z+mEcw1ncxm+gZfqm6E3acfuu73QZeL7IKUpc64cwOoZ5LWtqavYaC0d7oVhQ391Kjk58v3Pcuz775BYnuC9Emwvrpr4Z2HOyNDNs1Xb6Ak8CuG0sUvpIKTnLJRfqZa1uhceKkQs4mHtKpy+0eiXyIoewP5AvBhKdWVF/qvhWAyg1KbvH5QzfoiypHpQzKmEaphQJQI0QcaotuZ0p0E0Gm4REX5nLWRiEibe8vt2gkf3qqIOaunvXi4X9NMmcLT/+u4cJxYwqpSABmv+XZkDc1GmI9Xa/N9ZwaiGBKX7puJr1TxY/v4G92pqgO1qB8QMwxxaEW5/odog3t+Gz4fYT98eHIHEa7w5howE8cA0y752e2GcwRl2UQ+TA0I1sbQMXCGOGZV9sylHscu0x72dX08qSPl2jWizVqtzxtq9b4xOsit6FYVE7QfgyMp4cR07m8JyIcO98HukLE8gaPUPrYr87BueYDBK5jJkeZyJ07rdYz3ZSIRCOCFWpz0g+mgg96zvBrmHy4snRhbAmbogYAqzVlqQ3Me+7CVgI2gTBA2NP3d3TIDnuufxu8VaNlG8Rd1q340JlkMvbtCB8cebb7o/rhA+kOBoB1LxOYFrXR1fcC7XnQV/fsUmqIlBKny2B45xYU/JQXAbi/eXKhQVofGJ8ioMqUyHCsYvBs2bDD6A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Qowr4AZLLQj+UqPikrOM4ucL9GMDzidIf7GB7lPGlsDG5mVksPar1jWiSY6KFNuHEpcthT92n4x61HbLww+Wx3dNjKjwj8S3vyLfNf+865mxoxPUDh+FHyBPF6gTIVgfJex2f4ivVSIfXPy/NseZ36eYqZGyPyi0I4wnFdZdXFcIaa3mHCj3c/bOk/VUeNfoI8LAxdlcbDfrujkpJkuHm6JKLNXoYxhQP1B00YJiWwZnLdcxdEKWbMR1abVUDEps4hIpDFjEVuu9aNnA2MhNEqdI927GepPa8qQqJDC0+b/RczqSuVJsfc8mLbaGEmuxKkXbhwnLPjPrENFgf68JvlV9M3RJ53LH03FCbRfzYvvU9DIqrsWQDBCV/DELJszH1jY4pL/ncvve/FRivWPApAnHzB60VCzcWMkUrePZBoVPVG9YBS0MefnU+IiS589dA0wO9CLYGJYsn5O6+Il/kUu1yb5ruKqH63+dxS8au5R+7ADuc2D/xTkHJj1udcsAoVg+xD+cIqcgQqTu6hWWtUEW5HHcH501w4NAP/Q9HzCh58C6ELoH1UFd1Gl/OFH56BFhb8TvFo2TOT5S2ljyz8zIz/Fh0EPTW4/baS8lU3U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5b462ac-2ad7-4694-3ed0-08dc36f186c0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:55.7156 (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: 0+k0JWDUpeklCiAEUXiP32Cce4RtsebKAJSVL3tUI4E7WpGRSVQDKVqhgwJWQykIQ8KL+tUt0dy0o79/Ey+dhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-ORIG-GUID: jZzdI_Wlr3GJ7j1R35uewFlI5xSYNn7_ X-Proofpoint-GUID: jZzdI_Wlr3GJ7j1R35uewFlI5xSYNn7_ 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 bdd0acf7fa3c..08893b4a25c2 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -916,6 +916,65 @@ 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) +{ + unsigned int logical_block_size = sdkp->device->sector_size, + physical_block_size_sectors, max_atomic, unit_min, unit_max; + struct request_queue *q = sdkp->disk->queue; + + 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; + } + + blk_queue_atomic_write_max_bytes(q, max_atomic * logical_block_size); + blk_queue_atomic_write_unit_min_sectors(q, unit_min); + blk_queue_atomic_write_unit_max_sectors(q, unit_max); + blk_queue_atomic_write_boundary_bytes(q, 0); +} + static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, bool unmap) { @@ -1181,6 +1240,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); @@ -1252,6 +1331,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); @@ -3071,7 +3154,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 read_atomics; lba_count = get_unaligned_be32(&vpd->data[20]); desc_count = get_unaligned_be32(&vpd->data[24]); @@ -3102,6 +3185,14 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) else sd_config_discard(sdkp, SD_LBP_DISABLE); } +read_atomics: + 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); } out: diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 409dda5350d1..990188a56b51 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -121,6 +121,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; @@ -151,6 +158,7 @@ struct scsi_disk { unsigned urswrz : 1; unsigned security : 1; unsigned ignore_medium_access_errors : 1; + 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 07d65c1f59db..833de67305b5 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -119,6 +119,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 Feb 26 17:36:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 776132 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 37D6413249A; Mon, 26 Feb 2024 17:37:43 +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=1708969071; cv=fail; b=X+FlbYDhDBFwAZKdcXMh9FIGFBSr8PQTBcP54DoEu/hgwEdqfuUpSjEE8yuSx9ajxVXUvba5Jo0VmgXyE8DDlG1cedu9oUyMMvNbDCVCT0vhGWtGwuYF1cl+8NHUchX44wf66RFfjMSHA8f17aooZk354jqix4vISgArXSXsuCc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969071; c=relaxed/simple; bh=bYjgkOVGJO9/1RyNkJkkKNoBuS5etfElAGPPOyihess=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=RGN3ZCNFSCyXvB+DutOIdNpow+VLRuftk2K0SlaWjMA+5HzlyM2UYS9Qwb7g2KWFo+Ok1UG3sliaqoOCvaObx2vPCow3U9316wA7CRtn5k2wR6k2PnATKzyweWQUxVf77Eg4NJpwp/BEn1Lu5AB4B+kAHIWICBrdfzgmlAyBJjk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=eLNZAyY3; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=xfDFumGR; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="eLNZAyY3"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="xfDFumGR" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnLLO016090; Mon, 26 Feb 2024 17:37: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=b+jCbLIZ8BSjEGyQ0N+tiR21/rEIvKGtJSGaf47OfQg=; b=eLNZAyY3zd2ZJD4aPozD9Tos/41r0liQKApmteAG8q11lXYXNtbWjP8Nf8+tB19b0eVc nSj+yFS9NxSE7KmyDKtVelYOCW6pCJV6tHVI2udNPuwBIQJ4BiiZ//b0YS/quGjCHy07 qLoXmIxTedoxwgP7HYPlB8twnC+WNU8IWmotl1Dgy/Nxe/LKj94cLz1NwOKmXqs7R9My sb1I6W5YUKWe50r21w52qfuewYWCLme1aJUJhpPfmQCf02zft5fymmiPXFn8fNZx1EaU F3Xszj+Ol1/L4jBi0lhxWXg9QVELKDc/5RZ5o08TiEj9porE+x4f8QGnUPwAAZ3cnleJ /A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf90v5417-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:37:02 +0000 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 41QH1qEs022365; Mon, 26 Feb 2024 17:37:01 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w61tvn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:37:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J9bj6fonxkpoCNp0p5PZynJZmEKRbQ+8c9fjhiaNYcm/E/XJQN03QwnBewDH3QrX4jn98BGZ8yQeZqQn0Pft31wOV4k1j/Ca9N9c6GvVYa/9uQnqurRrNkKp5w9AgOPXHk7Jhh98ga38aNzL41ZlxTR+wsPhRGo8Zubf71z01cR/pbydFZS3FEJ04U2SiNYv37fmyUdwVGl1jKzZZezWVdR3X3wHCLin/rIKIVQbK5VutwBjKxGxUPwVi3lDjtxrj8RVkHBd0CMBulMXFfiiuqngGzQ3qPey1dmWbzLhBXMadMI5yqk49e1JzxFYR6qLMkHbNpEsWbROcsRxjKIT8g== 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=b+jCbLIZ8BSjEGyQ0N+tiR21/rEIvKGtJSGaf47OfQg=; b=IJK81Gelrmy+wEJRDvYqQNQh83h7Us4YrHrLnS2gb14pzwiX3Xiv2eJbSj7VytdWrm5HsAy+CP8HfBEc13z6HoV9skrUZ1th6tBvdvKK2zNG7ANxZ/GneOq9VUS/2iwz7p8LzGXpi5cFS4JRVRXpPVsdNBSYL2pct4e9Nnhw96dHGJa8xF5uCgYvlBXxU+zpCsMBQi7gnIGv9e1uq5VtyPKfZSPgVifPEVLBoYjZPNuvMA5UXgoo+pFAot88GLFks99Tyv6VWxeVWdjgVRR4Yp+1tflQ6ekbajCEfEA2lWbBW5H2JpUPu/2fq+e+w+zWd05Be2jp97iOKtlckeo/wg== 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=b+jCbLIZ8BSjEGyQ0N+tiR21/rEIvKGtJSGaf47OfQg=; b=xfDFumGRFqYUBvq3ajMwp2OvWbBXW1Kd2AIarflpbTF73PqLQyKsa514X2MebwcpomPyz7Spb3lxmQMFBS0GTV97/ZptmwqNISD5cZ1bOGPh8lMjMu6eM1stJ4TSaqDIbUyIRE08Tn1jsngZr+F1Ar2VT9RruLzBgiEto3TvfII= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:36:57 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:36:57 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, John Garry Subject: [PATCH v5 09/10] scsi: scsi_debug: Atomic write support Date: Mon, 26 Feb 2024 17:36:11 +0000 Message-Id: <20240226173612.1478858-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH7PR17CA0062.namprd17.prod.outlook.com (2603:10b6:510:325::23) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: 483fac30-8faa-4829-0eae-08dc36f187f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Y6u5wCKB9fIvyh6UEmQ+FlUxfb8s78nxx9T0LwNsJI/eRJUuz3XAIfRMt2IkOfW8V9xYFHqUG00dXzhDngKBV++j38vlLIskJUROXjJ7xfKbf7PrV8LRYg4slHf2KQMvvjWc3McRnBE/uE+flHxuzWh/iXSrMgAPTspjzDV70gvzN0avsMWS/46zKmCl541p9KkAg5YrE7zs49//8Ac6hlpTuOOj31CuZG0lL3OCWwSMwd58To7+nk3HUqPONnqZZeOq7gDLm8gr6cnI2Ie1ONKeGBKY+/9pQ1Pl6uUGFSgV7Us0127InLUMvPlhFL7qMBXDQytkE7bTpRzX9qV8M7Ldks05KYmWuxSLVEvp1R5sQL/c+hqKVhxQdJofDklbJcBjlw5vG9XcWTgtJRKeIYMubjcc8IyXPXcNzCAdFQs845UI0l5HtCscWAcH6oIm5dZzpa1JGZ94722KXWTCHMS7UMbBfeVnvfCgGYn27XWVMzEKfzDR/U+uGwG3SVHFs8dq9AHIEvNfLbhvOLxza7KQzd5HoQeN8DnPmCmbFISeWUX8jUdaJmYUqLQ1hTO17PTG3qpZhBRfwbBU3DOEa/XJgXGQB+GonCMwnTc8wiYpP3/eQCPXjgIBRhcIZ8rA3swTh96WdLkAevgUPqaLi/Soan6j52VgFDqaH893ieuFv1oWdYk1yAUgva5RnbWWJ0FmzPHpuFoBdd4P/g73nQ== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1Ti4j5YO7ROdu81sOQRt5upROvG6uPS7PPL1zQ76AbVlJU2SSYZ3eFnJ3wEiNU2grPox/RCPnCP6vhAxFYg9e5EzR7Hrl03UARbt/xYEIy2xZkJAmQfxwzLwkToMVN5zVIgzuKkcIkXbHvwWLO/6CUUP5bXLjp7RJPHc1dSBzVhEOUqrqFieX0XMxZZwo+u9sUwT7Mqvbnzsa+Q5GAzbSHqpcKz2xtjVNT25Es7vYqQ2wbs2ysn8H2AAiqDc4HsSH4Wr190kKZxeEUHnpBZqFbO0zVpZ8qlqPVS9caVg9qnhDKTgIhKTDks6sS5vvsdC11r3R2e1m3TeAyT6GotcqsQiQ9b8B2rdfXZvA0LI1C9pd2YqmK7gIkLJaqWxZlfTr8xuvX11itODJpXjBnrC5P/kCpl02SPW5lIli6lV//vYe1rhkmNsH/NbH9ekF5KB1s5jENR5M6N8nCDE7hl7/qMK2v86yqD/OdPRNRLJLOqvAFmQqgmkritZfHfXUuOMahYgu3G/QP9jw8CrPbHDc3h415IwcDjxUU2E7U5expxLMwUMmDiN+S6Gb0iFnL6xb4nUqeAkUlAwefH7A338e9KUxE6BGWARR8zqbnRLxBtd/jf8rAO6ZrC9xB8lIWDKaRv9k9k9VTxPinMoZYqv1kF0U1iJV9G4pZqivS5oBqlejYYxipdjjZKz0y3LIOP2RVvf6fM0Y9FniZGK+YZVw5GV84y9OMa3W9aZHLtnfkPCQw9V9dARnN4Z1Sdi3JSjiBGsSxqlSufP8kaOfG0IctlLVc6OuBVGGDInx/P+PX6vx8i0e1sU/CwXVlZxKR3jvQErk+jyX6Shkf+kOG4Gp6FrMk2CwTyqI9WTazxeEZavVKPYUPdnjeeh4FGDN64wQ3GlEwU8KEgtmVhMuq9gehAwj1mkd9fyUgna3toLBU+FyIFGLatMJA5aikw6UPCIamVT0jO1iCBbQlWcN7VdnKCHQ2ET130pZIZo3xRIuxDqHE6zgsEBBizOgbw9ESNxQgd4g/F3GcGzHa1dgiv3/ZfoUS7iNQcEVInd8WxyUMDjOAOBkW30aAc+7N59XdP+Q5FLXqO9NE8OtxtFyFCBMsl8M/7BaesomBTt8HYAJO0dS3Vl231g4ScYGKSlc/LPR4RmZdbnM5T1pEHC85P1TedEhSamNyt7s7E/zBwqkWIP7QGyPchHbZdp6yW42NIqVP5HXbh1TxUcQZq3VTpBFdE2YPgbihDrLnCdi+TeE9COHaNIsN/2S/sGtKBc4SuA6DztcNFQ36V8tfYhy803b8ObHwMWwvkHu+9LMvha3uEMj6CgIBS/RmQGS7SAMzWMlNSO22fv7wRK6YbnJ/2FCYBA1jIm6yU2IWhlCq2SD1RwXp9IIoHK/9EzOj9XG8knadOuH9plIfm7IqtxpXuhOHJUDgBzJltYihGJPCM1zuGBvG1THDFUYF4kmYwotmZW/BztWLcts0oZPVDI2AtkomB9o8fHFm6D4OWtPPx/tkaAQ25N8kFe8b31wXrK/KaUreaaiZcupZxHFCvfN1dIe5Ib+kNuL4SeNUON/avjGAdWlXu16Ei3lkf63ktw7rrUhVjt3bh4T2GDDckgqb/ILw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: kpAls+MRWDtXJTiFJFYC9j7/O/mPcy0IfYS1E7PwsC6ZxUOIYcW/O1uhA+Luv1WEsSRWrcpbZjBZgOmq4PAsi7fdRbqihNfqDVbTfxOC3UvL7vji21jKL931Vw/CPSHaOBcgiC/qAXnrwx5ARs3XByop3mCZVuhJnS3N1tcvCHTivIxtyCgFBRPc82UUn7EyxqBD/qTjoye4to8YtMwtuu8upWwomPjsugTCi69Lw6fj9NGdttzv4QAFpVzhQbhUrPoAW1LbYBxTfLr4jn8aSifWa9dneJ13xVNVdYGXtKk0SgS+A+ZLUrDNtJFyT2/MtD7Ob4Ct1lLIohhx82sY2QQ6VQxwLMHXz7DClCqNYEFyb7Hr/YwmhnxqH4lEgFYktI8VyyNOXYNrI2QgXudA3mIAfpeI9EBnMr9ZnOKbOeYjaYJ1r4zaq8BxF1skxh+iuCKFU7/f3ze2tTZ0FKIhLB68fnJF26sbU7TnTbd18u+AfruCxYYTbflpAYuT6HcLIQLmCsRLvwsb78BPKh3mjuFa2+zfHs1Sm2IpqnOg2dRMg6ynBNqZ6tPTRVKdkOSwnhXpOFyEIH8uWspvclUH3SCrm7faLeoXArV7KgcIx48= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 483fac30-8faa-4829-0eae-08dc36f187f5 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:57.8080 (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: G7jZI/WVA4XUJziAFnRXbfPMFkAOcYwX4AuJMOHaU2PmKXKebYZKcYJ61i5dKEWr/Ezh5cyaZjpnx+GMX90DOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-GUID: hObtNG5m6Yf8iap01fxWli0FNVOc8xOx X-Proofpoint-ORIG-GUID: hObtNG5m6Yf8iap01fxWli0FNVOc8xOx 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, 455 insertions(+), 133 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 9070c0dc05ef..77222376dbb7 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -68,6 +68,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 @@ -102,6 +104,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 @@ -151,6 +154,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 @@ -373,7 +382,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 */ @@ -397,12 +408,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 { @@ -462,7 +481,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) */ }; @@ -496,7 +516,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, @@ -544,6 +565,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 *); @@ -782,6 +804,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} }, @@ -829,6 +856,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; @@ -1180,6 +1214,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) { @@ -1807,6 +1846,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 */ } @@ -3304,15 +3351,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_write) +{ + if (atomic_write) + sdeb_data_write_lock(sip); + else + sdeb_data_read_lock(sip); +} + +static inline void +sdeb_data_unlock(struct sdeb_store_info *sip, bool atomic_write) +{ + if (atomic_write) + 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) + u32 sg_skip, u64 lba, u32 num, bool do_write, + bool atomic_write) { 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_write) + return -1; if (do_write) { dir = DMA_TO_DEVICE; @@ -3328,21 +3598,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_write); + 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_write); return ret; } @@ -3518,70 +3793,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; @@ -3591,6 +3802,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: @@ -3649,6 +3861,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; @@ -3668,29 +3884,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; } @@ -3698,8 +3918,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); - sdeb_read_unlock(sip); + ret = do_device_access(sip, scp, 0, lba, num, false, false); + if (meta_data_locked) + sdeb_meta_read_unlock(sip); if (unlikely(ret == -1)) return DID_ERROR << 16; @@ -3888,6 +4109,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: @@ -3941,10 +4163,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; } @@ -3953,22 +4182,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; } @@ -3976,13 +4205,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); + ret = do_device_access(sip, scp, 0, lba, num, 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 && @@ -4089,7 +4321,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; @@ -4132,7 +4365,11 @@ static int resp_write_scat(struct scsi_cmnd *scp, } } - ret = do_device_access(sip, scp, sg_off, lba, num, true); + /* + * Write ranges atomically to keep as close to pre-atomic + * writes behaviour as possible. + */ + ret = do_device_access(sip, scp, sg_off, lba, num, true, true); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); @@ -4171,7 +4408,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; @@ -4190,14 +4427,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); @@ -4208,6 +4447,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; @@ -4215,8 +4455,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", @@ -4233,10 +4473,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, @@ -4379,25 +4621,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; } @@ -4441,7 +4688,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); @@ -4457,7 +4704,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; @@ -4570,12 +4817,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; @@ -4734,7 +4982,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) { @@ -4756,7 +5004,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; } @@ -4802,7 +5050,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; @@ -4900,11 +5148,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, 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) { @@ -4931,8 +5238,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 */ @@ -4981,7 +5287,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; } @@ -5008,7 +5314,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); @@ -5037,7 +5343,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; } @@ -5080,7 +5386,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); @@ -5109,7 +5415,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; } @@ -5160,7 +5466,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); @@ -5188,7 +5494,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; } @@ -5215,6 +5521,7 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) if (!scp) { pr_err("scmd=NULL\n"); goto out; + } sdsc = scsi_cmd_priv(scp); @@ -6152,6 +6459,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); @@ -6186,6 +6494,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, @@ -6229,6 +6542,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)"); @@ -6260,6 +6574,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)"); @@ -7406,6 +7725,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(); @@ -7613,7 +7933,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 Feb 26 17:36:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 776134 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 D1251131E26; Mon, 26 Feb 2024 17:37:36 +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=1708969058; cv=fail; b=L5z7iqp5povEeLohPfkd4TDQynTzTrrWnMpkqgdoywpOfrp5pBO113obSySV267LrRh6BsSt0zBVL9sf1LZdj1fEoos6TMQ3NIDeK9E3lY4x2L7bI+CmnxNCv1AxudAlY8TVwmvs7vAYNMnLBmGdTvf0p/h/r8pFYSIGDvEcjaM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708969058; c=relaxed/simple; bh=ijYEFYFApduEOHjdwpDxBvdQjRcJGstA2L+L8N7ocp0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=FkpBMWV8G4E4ukaI2sKpS8RatxuYnlxqqCkHRKwR06ScZs4erPGkZcl9RbkFRLZhEJsEtRzVtNIPkPdtjfHv3P4WV3bIOmkRqFi8mkRSafHM8BhvLJReWRVDPR8hLyD9KOd6+iam8qbowLSopAA9nO0/2A4R/C59TdeAQWuu0ck= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none 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=gV0tYsMa; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=ungnzaV1; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="gV0tYsMa"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ungnzaV1" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGnGWX018463; Mon, 26 Feb 2024 17:37:03 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=EHCLtQsZ7lriVd7Tl7UNkBLv7DKwpFv8w0Tmh96SCxw=; b=gV0tYsMagE5fARjBTKvaEBip8roafJUtLHv0lZQcXq9TxJ18YxuEX+BR6STW5WTchF9i IOOJjeXMq3+gxH7Ixye7i5UBiIEo0YzHGnahhWFGD1PNozn30YwQjY8bJClfG3JTge3R EgYWwV1F1KQW6HzH2/ngcy72vzYxBvD8+59B56Trbp0m1cRJ9ajlYCTmI6m6hjgz4T0q N1ntVtNZP44uzaS85sslJ0pyfULUa0ASAgCRAPHvEp/+Vk+Tay+/PdbzG+MOitvy8pJv GP9P3aLp3bLdakp9fVJDHNpppGu2hKFyKv2OGpbFfjmLefNLTL1Q+gHELKYDxOMxD1D0 1w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf8bb52fx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:37:03 +0000 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 41QH1qEt022365; Mon, 26 Feb 2024 17:37:02 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3wf6w61tvn-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 17:37:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gTFY/3a2PNwPCmPr3KPf6a3usWAg3oxGYn4Ob5JwIjwK/YeuoNEwQRD555ZVTRkIAlD9PelkJRfag3A+avEzim/5P9WGntLwpF6Z1YE8YqadTRhs1NcJnEo289ayo4d27zqZHwTFFReLSbuQRVPe75o52H6NjE4IjcYRTxK2zkjhY6FCPDn2N+aRCwhaqsvfZdAOgMiup3jicY7vUVp5WLis0syfYqCkNayU4/4lpUfSZIvZR6NWCmbiB01OKYMiii58G4hPPZaKDeYFQxyPs9QUAaywo6LCegbreME4LJ8BmikLfu2mCDoqjEuV5jDlbyfA+IWyOP4feSFgsm1Hxw== 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=EHCLtQsZ7lriVd7Tl7UNkBLv7DKwpFv8w0Tmh96SCxw=; b=S4wGI4O6sv7ajAjPcNq/y7I4TnhRh9g05drunsRZHzR1BzqJForeoBiwebr3xD5gV8bGsqk/mpbfYuXCgjlcX7lV848wVJQD3V3sWKZ9L6Qz1wsUPDqs5AHMgxI46aYD7lBMww7huEYnkSNpiUxgGwEqCsXctaRAxP1KWX804g3JkT/Ymg5xe+4PGGWAuN+6wlX3VWeC34eInwbCBRrtg7OhC2IztSCs6VHppdUn9JFdPHpKwul6QII9gHObG46tX4fV4MTvmyc5cdG+edSKM3141MyBPuvdEGnxQ+P5LIKjTHQBBVYrQAtGOEUpnk584G8uoxWhzGn2kQhxEgn4Vw== 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=EHCLtQsZ7lriVd7Tl7UNkBLv7DKwpFv8w0Tmh96SCxw=; b=ungnzaV1s+W/iP236Rx0T4blqqO3rqy6UWy60CjM9Lf0rTAV0T8ame+HGzkB1LvliofI9fuw5ZQP//1Wy7hrwQ5Tf0391La7pBKZdxLGvrU1M6OQ+9Q1LtDvJFRQweiR1jwoL76VsT5qchvHT0XM+GAlOlCpNPEp2/gBt8jc3Ic= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by MW4PR10MB6298.namprd10.prod.outlook.com (2603:10b6:303:1e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Mon, 26 Feb 2024 17:37:00 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::97a0:a2a2:315e:7aff%3]) with mapi id 15.20.7316.034; Mon, 26 Feb 2024 17:37:00 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, Alan Adamson , John Garry Subject: [PATCH v5 10/10] nvme: Atomic write support Date: Mon, 26 Feb 2024 17:36:12 +0000 Message-Id: <20240226173612.1478858-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240226173612.1478858-1-john.g.garry@oracle.com> References: <20240226173612.1478858-1-john.g.garry@oracle.com> X-ClientProxiedBy: PH8PR02CA0052.namprd02.prod.outlook.com (2603:10b6:510:2da::32) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|MW4PR10MB6298:EE_ X-MS-Office365-Filtering-Correlation-Id: 64dfa4e6-d4c4-4123-771b-08dc36f18934 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U+C1oxC6qsTO10OEmudOx5aeM4wmWWEKRV0ZkeV/0GM61ZoDD9NpkVrxzCgDydPndFwwjvejhGQYPI99miDKi7C4H2Du54Dgq9tYwkSxHO5jgxCzjrmIKt/VbHjWUpZXEKd0q+DFgm1Zq3xgDQOpMIdpyyXD8JpN15y17GbWhdTHdEdhDyzAX8IRhLBulEl+wUu6Ym2BY4Qw2iBJ3JKH34KpzyCGMaDaSRvmcDqVzLJ+9R99yxLz5r4ZxqkiSk0w3bixHEi10oNuKSGBElbv+QOyYNmRi7L/RfVq44wmAnqKdrqDWQhAxOs/XfZ6emRdreLy96Y2B5QRGZM/VY+K0vF2kOG1+laKYJxSnW6gyZEGHKcyqPKyd5omHnff6FxJY9XzDx85fC8H/jqz44GKdGY/J6Z1cIN+VWSCa0V2YRZaS+QeefpxbtKoASUnshhbv2UwMPoXSONVYwkmOcEm/+z4rIZfMvZrg4PL8y/Yxp577wqbMACgNlQ8kwIfeqKNuBCEhq5p+QSzaRn4GRjBfWoopgjXj3wSEWflssX8f5wEiDalisp8GR3eBm9VsNj0oqU1liHlt5sJ6MrZUTYci9spf5PBAqTZeJZqdBiurwSxGxKRCYm6rvh1yZpaA+fo17dwZ0zV9Y8b6Cfrch9OcQnTvkxBZ95jb/BW7VsiPGNII7N6f2nLvThJ1Mks371cuI/K1EKMUe4N8H5W/Jqy0g== 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)(921011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fLJCqRBTwSJxh6z0LOZO0g/LZ2JV?= =?utf-8?q?g+k36U7enHePMWyMhjCKCgduV3i5B8eltJgSm7/CzWsI+hgKmQLma9/tb0w175oBv?= =?utf-8?q?1kXmakiXjdMtbf1A8yiG677t2glRDYEl1/KdN3DxKnlPQYVe5O1PNkIk0pHxO0O+Y?= =?utf-8?q?mSgHpS5tXeCvULQeAVw5Ncj/xJ4vpCzOQ+VZYHCBO58/nVHaHgih8Lx0oB7H1y3FK?= =?utf-8?q?ztHUSl3HR5XczhxWikhOM/0jWtppn+KY3usOWQVArdUOVEf+gKPq52ezg0SdNh41g?= =?utf-8?q?lwTffBIqu29DAy+hJoA5QxFW907Qz+TuoPcPUR6O5KR1Z8KPF+sIbenl8y/EWyz/G?= =?utf-8?q?dP7dg3y9eiwNct3yezDNosxyieEd8vigGZen6uxp0vi7UWF7K4IJd7MXoiBh/kmhc?= =?utf-8?q?GXAbrz5dOWwQnjZqtmPWqD0ccwIP9RxTJ56ayMI1Ma1Rwnd56C/9hdcEvBukxUJoz?= =?utf-8?q?o9oxGABBU7x35UNJE89Q/lb63Gyjqh1LCChFQUCA4HKh/EWVKtrVLp/54taqUJJlj?= =?utf-8?q?t7TLR5kLW5r/al4I+viw5qOkFwK/seN3GRlrXJcV+WWNWM2TM8U75dpEGpXZyWR63?= =?utf-8?q?039VQUbJ3SY6AZU2OiIFXyvJ9WNLXG2eo9k5MF2wd/poVyr8U7hpDjF/j81y+U+LZ?= =?utf-8?q?akIYCTNtQfiZfBkF0JoGyal56LTH9E6hCxoUDkELEmDnSdIyTv/5UxwmY8l8sLOdl?= =?utf-8?q?bFGlrjBzvzau3NTCvuzn95ULQxnCSvPFhTc+pQNPCRqsGizDw47vBF9+XTGQiTkRz?= =?utf-8?q?/FPS4rnX5U1H9lr5RyY+stci0lQ+Pj069sPU6XKRbxrF3H+e5vyHa397+FDW286bL?= =?utf-8?q?4+4Ma73UQrexlVixpXrRrJ15v+adp7Ta8SKazeKK0D9YQxEoP6lRnibfBGsCtJW1t?= =?utf-8?q?DcOusObDXVTKNlPfap0xaZL6G3MlUxRfVUgiu7nxXKUjwohPtQF7lFlnaEfnUd3aG?= =?utf-8?q?L305dr0PoQJRfhxiUUxfpnE5k3eqUZA14e7s5Vr77fiKbrx3b6XEKLFAiFKjUfyZB?= =?utf-8?q?nHg9o47DG1nTNHL7YPvB5lPUy0ecVj3TMDjtE114JPJAw+pIvif5GN/aObqEF93Ld?= =?utf-8?q?FBl41aHaJiK3WGQiT9Mz50JjuKUq72dbwWsi4RasVfNAFmLkXtPOG0qd4YwV9EnGl?= =?utf-8?q?oFlc5OvjpCA+Avlhwj9fEp4LEOkORWUDjfC/xfVCtISl5lpfcL8wApD4od9uQX3IC?= =?utf-8?q?+x3PKgSMKC6VCccI0AX/VxN8Z/945YJLBdoZwQXCQDgXPEiAJ/9b8QvHcjJ8tgRBd?= =?utf-8?q?TsNqkY/Jzas5/9SsTmXmKH3KtrJowcbIr1sqvblT7228A+3V1i8jk+mE7W276wIZr?= =?utf-8?q?vRQzJmftJWHQsosUTjvZKcZSynbshnqAirHzbnUyCmloHvM8HcqvANc/stw4m66DW?= =?utf-8?q?0hY5fZoHtW3aJnqvdFdN0LHLezahoz9Vb8lgM/9lsXb0YBuU1EFI76LUUslp4fvZn?= =?utf-8?q?TOoXIdpYTcMKCHDlcUBxXz0DCqS0WeIC86Ws6iDLuDsiEf5QmGEwV4tDsw8VxEs+u?= =?utf-8?q?CF6WTsrJajRIcmb0v/CAfQrUxsTdyD25aQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: VUNxDd8TA27jIoGRA6WYBynaHKQwkKZIqIm/rR2v1665wXYWpjOKEABDSe3FUsNgjSJvCrmn8D2eupJkWMPrMoVUI8nMYdXehcUIeA4zhNxGB/ebhR6HKXCjy7npySi5lG14CKJXLL7amIUqEhJQleS9hL54Q3sPiUbAQTIqA9tn+nIPoykSqWy0REmSzwqD4/yxk2D7w5wjXEzD1oqRGQ+RGW8E6axeY678YIag/DdPsiF2A9lq4wk7sun2blcJb2BOwyETT8f/P+bTxYvp6/zM9sA1VaRCLRWMOoZ3EYrt9l1ot2IKudSIZc8IgEi/h+e5+34u094pRf7CTIb7J5zrzR0b8/7TlhT31f451pBGgi0OgSFUFdTQnWqeFTDD9rEEkM6S/81vye7A1OvdInCUd4SJ98ELnlyhzt3zbBBl8LjXAh7DYbXZok+n5h0b6TNhY9WC+p4cAj5vgBj+7ezVRsoxhd1jhY1ygYas08j+1p8+t56bdLlkAoQbCNhnQBEtgSp3CfZl0GFhoZ5y7LTYJQPuz9QtT/EVpl1kU7gI9GJf002Hl5W+fg/aKJZ3pAEjwIzc9ZKLd/i4Lz3lcBmZ4sJIVJ0/ARV+O5XKcaA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64dfa4e6-d4c4-4123-771b-08dc36f18934 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Feb 2024 17:36:59.9391 (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: QCTdnSx+3hZkgvowXs3mZYjocoI0Z/UBbY2lAR2IUxSL6zQi7ccH+A1OzxPbSTeSohNPW3T0Q6Up0YvrxPe0vg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB6298 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 spamscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260134 X-Proofpoint-GUID: RMdLPRbwlIK7S7P_wP3F92xbAzR6EV8B X-Proofpoint-ORIG-GUID: RMdLPRbwlIK7S7P_wP3F92xbAzR6EV8B 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 The block layer requires that the atomic_write_boundary value is a power-of-2. However, it is really only required that atomic_write_boundary be a multiple of atomic_write_unit_max. As such, if NABSPF were not a power-of-2, atomic_write_unit_max could be reduced such that it was divisible into NABSPF. However, this complexity will not be yet supported. 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 | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 0a96362912ce..13e0266b65b3 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -934,6 +934,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) @@ -948,6 +972,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_IOERR; cmnd->rw.opcode = op; cmnd->rw.flags = 0; @@ -1960,6 +1990,45 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl, blk_queue_write_cache(q, vwc, vwc); } +static void nvme_update_atomic_write_disk_info(struct nvme_ctrl *ctrl, + struct gendisk *disk, struct nvme_id_ns *id, u32 bs, + u32 atomic_bs) +{ + unsigned int unit_min = 0, unit_max = 0, boundary = 0, max_bytes = 0; + struct request_queue *q = disk->queue; + + if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) { + if (le16_to_cpu(id->nabspf)) + boundary = (le16_to_cpu(id->nabspf) + 1) * bs; + + /* + * The boundary size just needs to be a multiple of unit_max + * (and not necessarily a power-of-2), so this could be relaxed + * in the block layer in future. + * Furthermore, if needed, unit_max could be reduced so that the + * boundary size was compliant. + */ + if (!boundary || is_power_of_2(boundary)) { + max_bytes = atomic_bs; + unit_min = bs; + unit_max = rounddown_pow_of_two(atomic_bs); + } else { + dev_notice(ctrl->device, "Unsupported atomic write boundary (%d)\n", + boundary); + boundary = 0; + } + } else if (ctrl->subsys->awupf) { + max_bytes = atomic_bs; + unit_min = bs; + unit_max = rounddown_pow_of_two(atomic_bs); + } + + blk_queue_atomic_write_max_bytes(q, max_bytes); + blk_queue_atomic_write_unit_min_sectors(q, unit_min >> SECTOR_SHIFT); + blk_queue_atomic_write_unit_max_sectors(q, unit_max >> SECTOR_SHIFT); + blk_queue_atomic_write_boundary_bytes(q, boundary); +} + static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk, struct nvme_ns_head *head, struct nvme_id_ns *id) { @@ -1990,6 +2059,9 @@ static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk, atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; else atomic_bs = (1 + ctrl->subsys->awupf) * bs; + + nvme_update_atomic_write_disk_info(ctrl, disk, id, bs, + atomic_bs); } if (id->nsfeat & NVME_NS_FEAT_IO_OPT) {