From patchwork Tue Mar 26 13:38: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: 13604181 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9CC96EB62; Tue, 26 Mar 2024 13:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460376; cv=fail; b=DiSUQanYZi3b4bujZzCOp6HTv93iGPYIB93y4jMFGO8u0MLrczerFF12nH50Hv2pUA+oceWSTMyowMa1XmThHWNdGQBcJ1QBvK1d489CFuXtlbwHRm1Tad8zXxDTgHRpV7fyPq+X6pXv1WrmmrxTswouJRlNFjuwjo+KJW5gito= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460376; c=relaxed/simple; bh=5IJeWPme6owc4d9J4rB7glUCkUCPJUFHVyjS2fSMKLY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=a/mKuOBk7akpMfMxoaOPH0/pIxp9saXeEUnFY4/WlZcZvefhSWfqlwEWa2bqOSVRdyeGCpmHCr/7VpmwaAFMPDHG45s9U1QC0sQ0PWvJvdsOzKtncx1l1o2oD+PbPVNAMYKqlFlzoLoEuvov0LuCil7DQxT4G913q6C5qQhYVHk= 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=WCm2MeW4; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=yxSmeziN; arc=fail smtp.client-ip=205.220.177.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="WCm2MeW4"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="yxSmeziN" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42QBnSMp009002; Tue, 26 Mar 2024 13:39:09 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=GQqyK93YBqEEnd4dsp+niPoiL16LGfXp5Dj1i2cLIJQ=; b=WCm2MeW4JK3aA33fT/DeN2saUXlFxK2WI96f21MqWnhLFrwr/nnNuaSX0beSK5kAL/yL fipS22UkUur3sdu+hrpGQuGU2DedHV831Ji3suZ+lBJKK6iTxI7eisAp0SkzQBUKqYGi FQPWxgujTzu8VAgKgHGRwkypXoxMt+3RgPRcFnMm6nUmkfDgQS1WXaZ5Y6ZG+bas726k PvJSn+9gVmJPMtljdATEJacudQqcN1St+9sg5dHNvw/wLxpz6Q0Hp73b/QryVe5rvF35 /B2IAKq8bZDfzWe9Alx+KUETgam6miiQLLzPDhDj18SO4ZdrHyIFsRdjQmh/tx86OOur 8A== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x1q4dw1nk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:09 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42QCMUGt030865; Tue, 26 Mar 2024 13:39:08 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2041.outbound.protection.outlook.com [104.47.51.41]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nhd8mbk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k2G68ux9nrYESTmoaBlVzeYOUCmD/xZeYXCON7QsE4NprbChwxdcUZXVhM2V33MHrdOHoYx2Omq9YRm/04/xWLOWK/gnZK86I9JUXco2QcjbJ8/HqhwDc8X95O1sZbAzH9Wj14OQkQKgPpFwXJD10SIxchEzT1vOgFLe7YagwriVsrXua3Y66jMdKihJYSAI7h/SmXxUlzf926sOpSqa6X8f7+b8mGa5T07lOujkB0GH/hAiuRhNgr0bG0cqgJMFzu8Zv+UlxmQtu+/JQYKieeyVQqp16Jkqlb/Ibzln8juCTV56bSU6AAp0rG7FVYMbSt9n0QY8TaTShTNcLrv3Zg== 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=GQqyK93YBqEEnd4dsp+niPoiL16LGfXp5Dj1i2cLIJQ=; b=m2erO5on43cpy/iCSD0+cSL7kuxyZEst7w+v/GEIwl1zRayvZg1WOl0Oa3TfvI9dBbIL01htj0CNtpDDsbjI+WxeLSklJKTI73+aWTiW3OMyoKnjiW0e4UJ4X13Cx43funyEnjKdm4CVgX7FXUEWAWFKH6OIb3ANvEqjlN8j2z0QdmVkuOv6X/Mmk4HsvfGDS/gI8SFA/W7q0+D++8u/AX/hvpgJlOXyAYCj0otjKmcC9RT6Xh70thXRYzru55U6YiDq0zQwJ12QdKdfolxDzRY5h0MjeFR8hh4UpF9LzeZb+Co3/BmrBXsIfAl933ML485JzB+QSoyAIxD08TCDXQ== 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=GQqyK93YBqEEnd4dsp+niPoiL16LGfXp5Dj1i2cLIJQ=; b=yxSmeziN1bjyJMI398F8hUIHTf+Q50QDm8cJ7BPCOcu9D7PWZyPQ3iNPePXDp+/fCOk6K81RA08RJWo+b97X+1cfKeZjWioSRVLgn06SVA8LFQ4cRla4hJ3zvb5UzQjdGFSieQVxXGww0VNnLI1I45nVOgAvkhWEposlxqrwgyY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SN7PR10MB6666.namprd10.prod.outlook.com (2603:10b6:806:298::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Tue, 26 Mar 2024 13:39:06 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:06 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, John Garry Subject: [PATCH v6 01/10] block: Pass blk_queue_get_max_sectors() a request pointer Date: Tue, 26 Mar 2024 13:38:04 +0000 Message-Id: <20240326133813.3224593-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO2P265CA0009.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:62::21) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SN7PR10MB6666:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tn9lz3p8s7pnxoWlRxbTVKs8uGYT56mMIioha5GuCRLH93mb47yHqTXAc/BOGaWA/Xx+R5Wgn38hrEruHR/dRUk+xvo0LNziXwmGItTjAR3HKdjnE2ZBOKHuqRZoIs8X/HW+XWvlwb9XuGjm1ct6brmLdk45bxeyZRxIJOhYwPQyJ0cxzXxcOOLaqtWZIjxuq7CdiKNeoUJSR4Xv9tEZCjkfTgkFKAFyoqw+CaBxueqa7m1BPqvKR9Wb9KFABjR8gvbS6Nwr1+6CcyNimUtr2McWIUMF5gpbr42VhD6NBHI1uBXJWbYYFGhXYwsbzlYTWktgikTrLVVUUhkVhAqhc3qs3JHtxuIrZDwXPXvbMBfzrEqWXr+AYxU5KazrSrtCHqa63xCDI5RbAnxPy16Vwq1oT3JWEBBvRkZTIttElQPafl6dBCDf7jHN+mGYo5uyZSg+0X5E83LzhARS0Talg5Lf5MNr4xVO5l4JaIBQlFQEDJG1vGaHeLhEoWNeKCRWxXA1kdBnWsaLJXBANLuaLm/J5h+PQwzGqA2J3Wt4rAFIhovFpY+EP7gujS+GdDh24Q0mnaHRQssLsrMf0HN5u/r+BlPipFwRGM9J0aaZQUZDFOErZ353gQtRW0s5wnRNDbKXqA+zy0NG7v5RKLF8vacy5ydUuctU9p+0u8clc5HPvePxq7VQ8cGAQTTA4qbXp2KVZqrl6gtqOpz5kue5wg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015)(7416005)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tBWFsnwgiwQsEcQ79GDU0x+qtUxBAmhhZwRKop2/zoMsdjdW3VvlvYYJOM83c2BLcE0ZJWggqmkHwmS0/rktwHLv5EJj8QZX2XV7OcrrbQlDMS8O0BX4la7Myx6IH6Y8LNofNLTTIJAhpSVwUQ7Xayc25hoLfqM1c4upnXpXkWAwu559WYp9WmLyrukTwG046wI7lE+vFSSiPtdbg3ILRlKvzENC15ZBJOA/tGC025BidIV6wIhEMCDFCwd77fU2BMT8oUi0SxsWm9XdCuAjyNs0QZL1LCkRKuWz93O0+9q/XwA3acA1q503O15QvYuT783d4R0W6F3UpmSmId4Wd69wEm0ntuzzMXbOq0MYa8H464r6sPROWVRyLtOSPn+jebqMjrdZVMdY4eYJ6JPD19O4AD0iT8zaRtC4Nas39c5E/VdD9c8Rkj+TtgGmMaX9tAvGJ9BkAM8ufpwnzYJxn2eiHPClWIkdBrL0H6LfK3LVt8OIsJuhS1+HaU76ZZSGBSht9FB/u3ApNYgYpQkXLsXm6UBaaOx6EKgKu2ABhjx/8a7cyDJTGBQJVu8oFBttAjpB7IuJAnN1SeDZPK44yHiPsQVhZoQe8+CXlM/21l34HNkm1REOYKv89xOql9XYrrSUlEDcfvu9zYXHmvkQlpAMVkC1eu/uR97dmJH6Lb2r3H3mMIrj7o0WqvKesDj8bZElxRyywy+ypIJXSwevj7ICSoVMkuAIk2AMOF1uPyUXygwfANguc6tG8jpRPT4OirevP5RrxUtQOpguk6CWiPEElXo5bLcAhKaYJFDw+tHphuHdMxqAnRVxc97413a68PIqzyQEZJPcF/3SwsIk86jsFKX4JVaHtWWAIIDfuJEEt1ffUX+zwYsO68O7nxcrRuyCQqfQqSzro9BxIj+hA1dvZTZfEF/CuMSw/Z4vNB6pqdMdF3OqHBCeSRjqT9/pEP35ygrcR/Up7HQhNG7aZ8MyVfp03oZ+Fw6HUolBfb9+O7awzwZCzQtIth6OhUmAxcKPF+KRQpRSdMtPwcv0n+w1s0rzdygIky++3BrFmgmgdLzVS3ViiJmqeuwAwXSf9aZWW0oDadUygDgbd0ODaH+hnX7CBGnUyqvMXzahoI1GiqMY6ZllY/Qv5TMkg/1s7M3fwH6z7ifsPCBTqCVNrFox/s8xP3X5Fnd1Zu97Fa23l51Ml27HWx7DwFZWwr4KdyidpCn9aLjKzFsh5/C/TEj2pzq+dZrAVN3MOX4whbDAb13l2sG4GBpwYGU2GJZH85hfqGFoNOvZQcKfAPWAF9EJR6Co2Xz6UFgP1+g/+kqNVFL0zDfWyYn4J6QIbsc8mTdsSTuQoNMTAvh1zLxiwkW3751eR3QYEsjU0WrvLhbBQEJhEJIqlUR0F/q0zDyyxryKOixwu60kC6lSymt30BmoOagZotPTSKm3JhpuaHYAhICIiVpqbT/Py4UbtLSvlxbxzecutxDvaJKRCBjMkCzC/Y6sayaqB2+LUiDIRneHwnSEKm/fOUm0+ZyQeymfnBn4iG9OpEMSlJoNn6XVLbHRNr7cIpfqTkbFQnx0Xv5BsrJvH6TT8lu2GXWrsJrKbWRCgPXlhle2qocVlr7C1A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: HjV/2UX0mmdMWwyBi2hGHGFyYMYWDlQ70OOqg2nc+NtndwlaCLuJqVUc55URlMNGlLAzI6vk2XWeK8CQqzPBFlhX4xq/1NzgXe0YngxjK+svQb0Evn+9NWH4hlJOKxjn+npzvmD2ukVI9NO5kLrCFX6ZNV2PKhJGmAaNb1XLf13RiMJ1DFcssoMeWr/rMhhF9IlbsMzN/QoWEYX0s93r3L3zjpjhoflRyNVjOY0QPIpRQOhh5um3dxn/hGL23D3NEmI4tVGu1dVTFYymaafAdKCDBr0rLa/iLXEw6d/XE3ZAKTJAj650sbrd0DPQJod84KknH2iRTQ6GBipG/eFR7Bv7HYnnYygcjAYYvHgZj9nSdDcD0KXXU2vQcHdkW/TUS+pXlA05t1nTsppThSlia2XzPKzQB++jNI7fwmfgyy5wSugNu/LuBuAC1IZo2W4uIwBW4WASMx0l9+yWGSqbkU8hVUJhrv8Q1ygOx/Sno95iWpp20ogxpsE5WMdCTw62UkqlC0N9ogcurRC6hc0JyV7sQZQW3i5lFav49IhGgvxZ1YWEBGmVOB2RyfRgb6kyPydBs8t93jFD2zGT5qL5squMm8kWZ0zmVxQOvF/f/UA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e389bc3-994e-4152-ed0d-08dc4d9a1b69 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:06.1809 (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: njMh0NhBJW8OTH0WoS7i2dY7tIso/wvNLl6GmZsQdPZgPDjMom8Sm16UGJupHZH9y1JO0H0mZ9tOhtbO5uW8jw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6666 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-ORIG-GUID: c6GExGfEpot8w4BCmWoWyrN2IoL3kLt2 X-Proofpoint-GUID: c6GExGfEpot8w4BCmWoWyrN2IoL3kLt2 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 Reviewed-by: Luis Chamberlain --- 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 2a06fd33039d..6f9d9ca7922b 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 555ada922cf0..5428ca17add8 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3042,7 +3042,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 5cac4e29ae17..dc2fa6f88adc 100644 --- a/block/blk.h +++ b/block/blk.h @@ -180,9 +180,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 Tue Mar 26 13:38: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: 13604184 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 A3E1381ADD; Tue, 26 Mar 2024 13:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460394; cv=fail; b=N/lu6q7+3OWc2+ilkavtavBudGndXWIZcNLLMOiywjrdNVBJP/ARUmvw/4gYpAw2G9XRN9o2OZz7xz+H7yXFElRMRU7v77se7AnRmOD5XGTHd6ARYB1euPnQhuTMqA6IZ59ncQ16RF3Bz44UF2u4AWWA3lu1IZeHlfFWhPkbzIg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460394; c=relaxed/simple; bh=jZu2x9dq4gx1tNyj0bQAAyplntekELCBatKU52MN8X4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=A+v/pCwjbgTE1nQmPY0GwxFpM0ue4Q9GSfydoBkLV8GS0VLCh9WtBEQjMBX9PqmZy9hQuej3H/M2+t2fPLqN2gjosT703Kf/OfD2qJvt2Gydb5KrUdZLHDrObtpawZLADwVPB0oGk4OlLczjPzZkxBNGTnLv4N/ovmumrUbjWmI= 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=J9Duf6aO; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=OcUm1El4; 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="J9Duf6aO"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="OcUm1El4" 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 42QBnhdS020657; Tue, 26 Mar 2024 13:39:14 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=J/TUfMjb+2DjOF3xWM5G/RwHma3NQe/UvvJbfwLYN3c=; b=J9Duf6aOnjM/z1XmsjIitRCpTsVh8a+kXfErWEEokxdf4Djh+lNVndEc90hZt3OV4FmT pYbewvqm+UJqfELlG91huJvNpz4cAUmkXMRLe9yNlbi1W2RdEIKqd6A0KTk6UDssXgum ZVrflxxVXl57AsGH1pOaz1cguQbnRrRt+u4FZkJfp5TpDt1WX7/AA2CPh7e9aOInvHiN aVVmHS2YV0Q+lvoE2wjpb8nDvHGMeGV83/DJ2kHrBkng3JbhsTQCS7WZnnYpdWwwO/M/ BYJVIXLoL/36S+jGhGlZnFtGaUI+xukvG3zLhLcX/X2jFw+7dc3YBcKegmon3h3srTfO 8g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x1np2d1u1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:14 +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 42QCMUKt017835; Tue, 26 Mar 2024 13:39:13 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nh77wku-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h6cT4/bjUGNmTzxwH/rNouJBQRsgXh9QPk/OOvpCgoe0Duslp8p7oCbBhNt4vEVGMuz+OtDjwgzDjoNVRICrVo7IqvqWkEidy8mEsCdFSo3BLldKGbyWtRbcxSrMQxoBg8H6vau1oNrv9Oe+jShOAX+/15e3X294PEwlva2uIM9iRkItrUePnm9pBTlMI5EMYqY64bf60pa7ZR/Y2KDjY4OZ/Z7KBaf+sTAxoh93fFTH4N2Xkt3X9mO1jtOJEvMS+S7NTrxhT4r4EHz63SBvBRRZIsjIu6jTrCvjF1sHBuipAtYo3OzF10HdoR+gubK6d3gG+zEQJb/s3nVmwfJKoA== 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=J/TUfMjb+2DjOF3xWM5G/RwHma3NQe/UvvJbfwLYN3c=; b=iroSNQtdbVKa2OKXcOMWlxTDzoE/jsoXsvcVZfRA00CHb1neqbbnfEyt1BmwIwggfdcj4N9LrTFw++PD/A+20UYYa8nzOxuV6jl4IydIG95HqQyMZOHj2gyBZC062m8aNmwRphUuoJxmwV9mOE8L5HX6lwBGRRZkM36kMwuGLFfla/ClK/fCad1biUvPcvvreJ7eZCIJAcfF20FUQbrEGPGHzRLtHeutYXhpKiW2ov/aTEh6djRDj8kEcb8Qqpr48DgeF2e4vcGn75+OUi0cZnSQRqFoXtkLqtD4OLdi2KaWuYI3cMxFpPTeJo9GYiNO8cuD5xIISSHFopqEQsjYhg== 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=J/TUfMjb+2DjOF3xWM5G/RwHma3NQe/UvvJbfwLYN3c=; b=OcUm1El4nQIkdQ6jDmziwNr+Cbm50U2+wIHiVTP+10AXXTEMGKq0UFEOgSXXUJjRyKdgqG2D2fsmGZyj6q7/Hyjii0ogElKtFbvnRho1/cdpzEEFsUiq4/Gz90jKW898zB9WGhjvfTh/zxCS17nOoGdjfV2P/13ozCMeLZdNnus= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SN7PR10MB6666.namprd10.prod.outlook.com (2603:10b6:806:298::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Tue, 26 Mar 2024 13:39:10 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:10 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, John Garry Subject: [PATCH v6 02/10] block: Call blkdev_dio_unaligned() from blkdev_direct_IO() Date: Tue, 26 Mar 2024 13:38:05 +0000 Message-Id: <20240326133813.3224593-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO0P123CA0003.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:354::11) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SN7PR10MB6666:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zkKX3Wr5fBPL2tMvIDauoQnAEBuDGtCqIh+WDz4eAbEmJxFYFl6myrDn76LK4/XtZXwRwMHm0v0ITCsUMvbonwFO0pF2oOrb6wQx6DNLDd+5Iyxd4ECWWukF4mZedB2OS21eNa8ZKMvgofetVGpJ7ih8Sx28nCQkdCQCFyOfrTJotG7h0xogp6oswW/ZzktqyuywHp1qlWAb9bZ+RclXDQ66opqPE+NberBZymbewbvB/plYHPWASTjXGdeRd5+8KIagzZ+AeILbxeBmIblAGCCnUFy5AsLCWYHy/o1nOnMcjTRhxxzvJf6zWjkeMeG4NmGAUqxHKsQmp5wsMnWvWOtcqCl9oPt8HT649nstTgwKu+UpaZSYv57LUfIB2GyNtqTKmtiXUOqKo69MCUFIf1pIGmIJSH0Ah2iekABZgEABKDWwZGvZInYMoWyHGJGQzagrjWXg4VVbIAcUtYD9mnnEn9RI0NVQHcLQsHqmGB6KSuNVMFrS5WS5V6iulkw7/O6GtCJasKm4ezsK8nhew6L6IS6ZBo7vk+b+Jm64WVhdXANpsBwELqkQc83PlJIb4SgvXPuD7yFAjkVcG4/NZvS0RSSzhORp/kcvFqu9NoV1JkK2DVEhnrr3Kpw0GdCvgILMFZKAA8O3VOdGkv9xImnhOKAgBp2EufUupDRfOB7WFntN+5B7ktAH0yrv5YcHcQEPQYvUmu5AVimnunmDfg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015)(7416005)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d3MqOsj5kf2E7vPND72IicNtot2LZrrX4fHQkFKU2fkGx8ni7pLQqs4jLYskIX0+ipcJ1vGIrhvkqgbmeLYAoH59EOWIyJwe7g8+FGB3T2W7/dGOO/CX730jGEonHCFaRF3LZI7zuRvlikwFFvDtbEScdqmVrYzSNndO2fEtDy9dmz6UdHlhpla/h4ifjZsHJOyujmmDAjwjkAfdO2zBBgy3cWdtGBXXpYDRJluxvgNS+R9OErr/xxnt3SLvg4SoyaZenUhWa4OyBjca3kOBFRuISOW/qgVOazszViD7iA6W84JU3rOikPKbHBam5puRQbu3//LP7sRDFgNWx1OlaJk7tBVzEsuPZEzLjRqh97cFN+wtw2HS3TLyQgoksCnZxgsgtFiCyGpQ2/lOywgVi02daF/UwXATtNfE8HxfBvrzt6cqxChmZzSn9LewBBiijRXBv2yPIp8OBunfDf7dDULcQHdU4SOagQJLurLSfS6318vga0UhLYbnE0NBeAyYWjZ2pD1TDsmI1w7ZrquZToBgRqK2gzlijQI6TySL/xpymoG0EN53P7+bRqIYbIT3tqZTPsZJwsDTqEwucP4Rfy2V5xmsRZ4No+RTeVcGfPxOifqa4hjVIQSUi14Ra9Dcb6phUreV8vXfE6xA0ZqcIfnXEPezDYiE0CFNPPuVTLkecDIzkWgkfApD7snNhC36AyiKQiFaf3ux5OY9aRoAzal/7bvZV3y1g65oCqX7cnEdDBHwvdjpF1zXp3RjG8KQtr7aQmjOEqsnH5c87f6OG1GWfkwyNhrJjz7LH2+26A66P51AYLCMVF9v5ADuyE4ARS4phu/okS68b3NEfZ1q+c9kh9COpJiKSZ8tCvWFsvK5iQ8EaGqDIrAOAxEnaWmMd9RitHkKhpcwmKznYQVXdy5cSw/osLYMpztKK0+4PvBLUAitdLO/duVGKvX2SEwdSq8q0LcKfxkHUBhXFwYVS/pZeEj70RT+V8R1S7ZjgATLTjlruxndEQjXk0v7LBLjePgpTvr9cTGWihKSZ0ohL0Zsl1VPvXAsLNoM1VhiyFBl/qqZADGz0/2rEl4l3gkGZ/TWIiTk//tpoWga/RxidbfXPnxOnUGO0+ZuwZAGDeRtK+owaSoyP+qwrWi5Pvb73O8dvuaIlAKbmZ70YMHNkeWCXJ+LIwBK5F/FAmmcq3KmUB/ECvQnyYijHACbclmwDeY0wL2GxUpSI5ktfdQVd8J2/0YQFIAKdNggyQqLFKZSqwXVCKw9mPixlOUx+IATeZpFKlo2TOqxhAHl0tA5b29/ZOA2Ljbh86FOc/BqEB2OymZw0RbB1du0HX7zGoPPMjt0s0pDH83KwkyxbdnonUFAEsc8p8JRaGL2rbgilqf4xn7OVV7WxqLVZD1iH1c776pBEmbNZrTr3ZyFFe9f4PUemVqK+ub5oDUbhh8TK3vjY00no8bI/qJX0SSlhls75d4tn40+0K7WxRxr2r0z3qVT/9SWfaHHCAL5cMdFVbvtzpeZPmfCXfiignUYtZgEpeQhIS75IB/qusquegosqCW80ilQ7fGjE61nx6xNida0qli+wU14Zz/xlj0AKTPEtvQqNe5jnc2+KJguatzFqg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: +E/UQAa8L8gM/I4N1optlIghwUZ+EpDKnXCReZRAaSMCK3ybbNnfS1zCm3dUftY3D8tdzH9TsEP59QtjrMGS5Yx50ETk44tigbbG6iag0G5Vgw/Sy+tOujnKF3GpZwFru7BGWXTG6d1B0kqasFSZfrWSxY4NnUTAQyBJa+4vx3ORgaf8TAUoGRUt5U/UUEsBGltl6fqBRAGkVfmdjgu0Qas6cscdkTKZqgiSpGndsget1uL+l8JmP1YiaWOtrgel2RR7pySIXz6DXpXcxYReVxgV16AGmjkKZ1MDPOhAvjOQiGYKQQ0+9IuakoM3rlz9wP1pU0VU/GKzYuUgjULX2yNbV+kFUUx+AHQ8lfhqNMheFVR4nucDCVdQTVExPItFSMPfTgEM3LwJXZZ0AHM0zv3qho/yEG13lHKUQwaV2A6c8C188YW7wuhFuQsZmuIo8JsEqqTNVC9qEVqM95nqyd1oxsbL7fVqJhi5Pjvn3WOFGWYkMRb2j7UmXnd2AgzcYWY8gns56sGfUaQNYzHNJ3eT/WiPOmLu4xUTtkfqdaLS5orMfJGAqp1FW/e+qb/NMoOEiF77nPW4h3RiyVhE0GvJApVcMCAIkhwUYEuLn8A= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fddac6ce-7ccd-42fb-a288-08dc4d9a1dc3 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:10.1283 (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: wTug9TCEiai1OH+CTI0kSK3Tj0VK4+8HjEP2v0bbkyNlzqMM0JDoq8+cS12aCXqbgFgKXD+WcF0Ymj7SpCgKDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6666 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: fD-Lx_yZaoTbg0m8CmJRz6KPv2ZEv8nO X-Proofpoint-ORIG-GUID: fD-Lx_yZaoTbg0m8CmJRz6KPv2ZEv8nO 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 Reviewed-by: Luis Chamberlain --- block/fops.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/block/fops.c b/block/fops.c index 679d9b752fe8..c091ea43bca3 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 { @@ -161,9 +158,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; @@ -172,9 +168,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, @@ -302,9 +295,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; @@ -312,9 +305,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, @@ -368,18 +358,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 Tue Mar 26 13:38: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: 13604183 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9161780056; Tue, 26 Mar 2024 13:39:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460384; cv=fail; b=aCUSQ+kegQYU2pRZrfJzVUqIVfiVJKp0e6dxzzc3wCUBKVVxNgSw2MPOQG7jVyZ7D7rqii0C+8kryLtD+FmJuhu6wiUj181JuwofIUOzjXqKVpfB71EftW/HfGjsbnwM2sTUHKdLs69LraX/JOhEql6QMUUObCD2nNdOMK/rUSw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460384; c=relaxed/simple; bh=eNy4vc7v4MD91pZQkkuJdnbfyPXXwYtwTqQW1aKAr58=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=UzaAfyz+c5Ed+19s0fBdSNAW6CVSXOaqYZUtUMZQS/fP3SCcJfrXFUMflNuK566YMb6FlUOItsk9Qrr8Zm3aaCZdokhw2WckCCJqbyEucw03nDx4mDs6HBh4gVYjT6eINDUhzlznoS5+FPBwVYi89X/RomhLfw8/zNehMrGUa+o= 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=VF8OMS2r; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=E+pg2pFx; arc=fail smtp.client-ip=205.220.177.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="VF8OMS2r"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="E+pg2pFx" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 42QBnTO2002350; Tue, 26 Mar 2024 13:39:17 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=lJFqGDQVuP+5yQVTw87t6ocgSqxEdIXA7qhdZHCTSo0=; b=VF8OMS2rP45dlI0ZtTLl8JjYbP+AZ0aYknDIui2Gcfs7M9Ottw1YpSgPgRG4kVANQEVx 4U/+BhQ983wfOkKKz7adKATmVGhoOzPnxodg+8kRFUGXv5TPTzQ8SnOcQSSF5hTdC4ea Gq48YUHMvAHKpI9t8sPRpmb7c54Gqhcq+ffoXhP9iVNOKruGk5OdHglt5slIYnkynqUt zWjTtXbohDB3pbncMPa4egkvqCCZC2kAYgw3L29wy2Ai7PGCkThy6e0yc8uoSP+/+s8i d0BP+JoIfC1V8+HeE4pJriqSyEFBOXRJWexXWMf+KrqD/+7WLaNz2zUQGDwo1AP0rTW4 YA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x2f6h3xcp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:16 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42QCMTQN024583; Tue, 26 Mar 2024 13:39:16 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2041.outbound.protection.outlook.com [104.47.51.41]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nh70ptm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fTuAPLC6VuP6asbdFC+BJYplcs/Ra84Qi6OjUcp03KUR5xm52s2ddiI/AcMeR/so+ZusO8nY5pDwMd4ukX91XxY1kmFV9qMhjth4iwgoXTJuYbAzjOcDF4RYnnFKQ/H7Kx9jR1zomQfBDmjKybtuYwfHTADKT6skZTJ4vn3HDvHfQ6v1rzkYV5Z2+i6nUuqwPs+6OqrZ/AadhmiLYlbRyaRoojV6LIVzLg19Xuu5ggdXT3ujHa8MK3zYYgxqabRPolea/D7KY0ZMPwko6Vq7umFqn2cGqYxJw5lLKGRZNghCtQqfyqiJGK8FkLGY/+f0n0kGsBWR64z5JERDsFP/+Q== 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=lJFqGDQVuP+5yQVTw87t6ocgSqxEdIXA7qhdZHCTSo0=; b=gBGh+NVtcmXaReBfzV9FUlxo2R3C0UqTDDCa4yWYOb4o7vhLN0Ktz8Inxk8mdiWrw3BwaOmGXiW/E1rLPRkoS8N6fkoaKcTRpFGN8JQww0QL4CGjQXjnwBvjOiSHcB36WFmizq6oDOIv14S08kgQv7N+QR1Kqy7BnAkiK+u/dcJsdsl79XsglVjz3txcDKdFXqsxC3yOtauoK1Jh1KoqU2DdEYCM195EoUy9RJ80DHteoOkKI6vkDMk9COpfhH0Jmw9XEFHeOYPNAv+rjbrtCQmB4wTRSaFoxlJ4ej41SB/nBK3RT49IqgkPMfxhRshNdTxmNa1iFl24O4XTWB6ezA== 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=lJFqGDQVuP+5yQVTw87t6ocgSqxEdIXA7qhdZHCTSo0=; b=E+pg2pFxxIWfXcJ9nxay1940xXKfadWvpIQOtIOHsRiGk5iC4IyYT3gt4+bkHywbPeepwGFT51Z0Uyapy0/sF0fZotftWhoSusuSLAH0yBxrhuQyxCJ1EmfVTYb4gV0gO1a7/JmBEjV9yqEED0e28hgyqVbj3YM/RUQl3hx+ijg= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SN7PR10MB6666.namprd10.prod.outlook.com (2603:10b6:806:298::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Tue, 26 Mar 2024 13:39:13 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:13 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, Prasad Singamsetty , John Garry Subject: [PATCH v6 03/10] fs: Initial atomic write support Date: Tue, 26 Mar 2024 13:38:06 +0000 Message-Id: <20240326133813.3224593-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P123CA0080.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:190::13) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SN7PR10MB6666:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nTddXkxPNiIHznduM1EGdtcsHYXrwfNyFlqB0fSp5JLg6dYViZ3tPjgGh8sQ0gxLRDKbsswRHvJ5TNBEWTk6YIaKanoesx4bvc2nhm5hOINHM9Nl6Y9sOpQ/PUsOjodJ/Y3zKrKrPEX7Lc3zIzmvoGiGAuBt155+xF7PUwqcgwPPhlsi4trbY7iHyEvt3P7/IhXlJDrq6i7eFu3y6nV/9gJEPh+glEax1ACCa3WNn5jFz8KFdHZIhh0ax00OrqvFmF24CKjZwBr2+1oHFzc770hCDmWSq2EJZUH0702PhgeyPgBn3Yyat+15S8gplXJvuuljDZnLumFKC+DcfVzWNlzRKADklrDWFswnXoWzm3RgzETNvSK4Ay2Inh6r4TCG8VbvhnB/Jt2rOMgf5R0rPncRcnGghpYSnHQsiiO2o+YKq4aojUCgBcIR5JvXHE3g/CEHHJa4vsX6RNqewgu+m68nws3/yCMaoLWhjJ19ypDK9oxv7biIIu/KI10iQ/TtvclhdUzEWR7Vgj1Z0VTUnh0+PGR1cqR84Bp8419F8LPlKD7AfWf/4sZiVYpGrOqnkA4BsADVKbpcS3dIdF/wCt288DcL93m7r9aNBvq67kulcLe4WkV6l/ufAFChjgUx8P19omxgG3txebgtSJK0j7AWYah9Kl7tviKfVgPb7x4T79knm3k/iHioyk2CIvkRhQElXNvqT/olY5NcRa0tDA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015)(7416005)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NqgxPkHyG1PTqS9EyhE6F95pEOl7vcPSqG7efHBDVNg6brLBJgtEQgWxgtY/KnrA//SYcMz4TlB9mpA8ljwgJgLS3AIdhFtXf1N2NbqLVp7dOg2Un0PgFdLnQu2Zu9FgmeVenZI95qy+tCiAocvU59oLiHjf4jpmsGeqT8WP2d01NXtOV5el/kNkpD0PeTEu7Er+PWhdPXEXN2C7TY5ZmN5spuSG0OgcdNHe6s7+T5j+ixzjwMdk8FWz3jcaH6afRxV9rHsCpJTWQAD614Q0U9z0c4rTXsEWRmFZ4tC00KSQ80q15o/q3CpzH5dWyHXsInMXfo0IBCUeZI19Nz0oqWFBA9i09nW0b+RjAUQTHHmbgMbgObMIbm5cVu29PgKtOHZ5ZPUOYsGRfkw/BSleem4oTrVc0rx3o8NxS6kLiy2pLRQrhxzKeqlQ5vAfmPFC8OxNgY0N5IHX0+d0jYxyjBcFt8ZlqPrQuhxchGqi1Rgv80CxR1Zc/qQqivHK30T3rkMF3SLffXmXGCK/K1Vu1M2/SJiWmSkfFUEXXkEo9iW9eC1z7vFtvtKh0VXjDuR4bpqIlfXLwo1pckLpDiRXsQDwYrNZwRYt2cENx6i+rqo9SvbGkYv98x0A3sWJXLtmqNuOeI6PobAB6fZhafqbXntHI9fKzwwKMsVByLfNmdGcZeoXuPE+Z47VFBVvAvu+CEceYXwzgM4/ma57j2xSai9eZcpcn2wE5bwdRDlLCQ5NAkLxDY1DoGnsSEr+xsPQaGG7shhTN76j+W+Avug0NkiHY8Xb7RiunrgsI1BbmHJyQ8gcggiUYj7gi6iZ67eIfFViVY5FaD8o1zuOjY80eJhYbtP3pM4klehGkzGG99UZ20mlx3E5p6smRLzTnK+EN//m81S8nbpuE8ZxbYfaMwdrZJQPIvKxmpw91Ss9io8ufe11thV3H+Oe6A8pwY3nacq6jbUWPylNxa5MdeVlXxiSnYGtk+mwCrURAQzTm2oUJkqxgnOdSkSQFnG65hu2IwAJ5/kL9hmhCdyq5cVKbnFYC70aJPhf4cNxpxXDN0ZFRb0GU2wMrTESUtwpjwJFfzueyc733vERNcLZeSMRKumsMSaBj7EkqV7Kq+pbg4IxgQCKldHqYPnVF9vQPNs7k35D5v0xpmHbpVozqpRRRKGwmzGE1v4DYrDXvwJqBkvVPaOYII7pO37GzbVkklSCFSZLF13ZOew5zEPe5qji4EAsWqozwnnT8TZx3WhLKxrs/leXjJ6yjzP8yQsaA8iri/O4bY2LiGoH1Vao4f62X1BgeSd2NmVxdllvzvPv94Xy3ciZ/g+kUCb0IIYWVwESDRc8v5+O9B6CbQR14qXdA0sCflRkGKz9/suRkdUiuxOQ8Ax+g5pRui8Jq40bhp6srye7duGnOVqZ4MCofv2Dg+D7rda2S8tNd33uuS4RbUVpQuFfTREmjo5juwKtFN8IAj427z/S9V6KTS09MM+OSTO4czDPvL601cazhfpFVZQBeKfCym8Y911VN0+j/SxkmNNhnxgIq6PNWoepsENvCVztC7sGC8NwUpCUB0aXDtheDLHhEsZmE+Ud/CSNKEiEuqxh+Z9JR3EWCgznZDBgtw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: LpD3HnEnN5/yLyQE53uSy1bJrc6s63awy0o5I/i6aFSe5x0yOuq4EiIQqxHbfpFz3rNWhVhuIXY8eLkW1cMuus/GVrn90q9+WxVbS51CW4pfKgPKZYBSd5Gz/1jhypcY1ZmftW3XOBG3KtSeTz6OEJ+tPKRm1uAQ3EegQd6kDkKCv2zdUaE6EPLkmXnTChLvJbK3XaqcPR/wBI5c6rWoA6LivCU5ATbOD3JNlHMj/IEpyH+XgxGnpqt4aKM8DLLzpHWkvL/nm1aVc8VQrzqcfO+/OaWUJU1ONkN+piRTSUGf9cEhfra/zJ/ty9sW6rsNyCaExCnmngQwON56fjjc3CGQLyvKWZcVlK7Wx3wLbMX4YDkB8Z01mB0vCm06jTGZCBpXSsnbCEu/mPxl9/FECih9jrjrbIWs6BYuVeaQHP9bsq3h4LmvjKwmym26XZpcPYGu8qwsxsa2hTQbWd8beoFLy0A/zFuZUqRuVnQAhWysSXCm6ePqSrKHDQ7PVQzdo6B0XL4aRZObV2qtD7t0NNFULv3hmPPITM619Un7kdgkkUCytxIElNe06qQN6A2lLBR0YP6DlUB9+ZO40OyrHZUFAlmuVs1WEV90PoKB2mk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ba5cdca-e015-49e6-b21a-08dc4d9a1fc8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:13.4946 (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: 11IgkXFJivE/PS22MAb6YfoKRxRCxvWBmKw00tenn2N89S7zsJyypa3hA+a1izlTHjZlpAuxFKonDNi5sbah0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6666 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 phishscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: TPJVMxuv8El5xsMmHwuSYF9cKliUh3v- X-Proofpoint-ORIG-GUID: TPJVMxuv8El5xsMmHwuSYF9cKliUh3v- From: Prasad Singamsetty An atomic write is a write issued with torn-write protection, meaning that for a power failure or any other hardware failure, all or none of the data from the write will be stored, but never a mix of old and new data. Userspace may add flag RWF_ATOMIC to pwritev2() to indicate that the write is to be issued with torn-write prevention, according to special alignment and length rules. For any syscall interface utilizing struct iocb, add IOCB_ATOMIC for iocb->ki_flags field to indicate the same. A call to statx will give the relevant atomic write info for a file: - atomic_write_unit_min - atomic_write_unit_max - atomic_write_segments_max Both min and max values must be a power-of-2. Applications can avail of atomic write feature by ensuring that the total length of a write is a power-of-2 in size and also sized between atomic_write_unit_min and atomic_write_unit_max, inclusive. Applications must ensure that the write is at a naturally-aligned offset in the file wrt the total write length. The value in atomic_write_segments_max indicates the upper limit for IOV_ITER iovcnt. Add file mode flag FMODE_CAN_ATOMIC_WRITE, so files which do not have the flag set will have RWF_ATOMIC rejected and not just ignored. Add a type argument to kiocb_set_rw_flags() to allows reads which have RWF_ATOMIC set to be rejected. Helper function generic_atomic_write_valid() can be used by FSes to verify compliant writes. There we check for iov_iter type is for ubuf, which implies iovcnt==1 for pwritev2(), which is an initial restriction for atomic_write_segments_max. Initially the only user will be bdev file operations write handler. We will rely on the block BIO submission path to ensure write sizes are compliant for the bdev, so we don't need to check atomic writes sizes yet. Signed-off-by: Prasad Singamsetty jpg: merge into single patch and much rewrite Signed-off-by: John Garry --- fs/aio.c | 8 ++++---- fs/btrfs/ioctl.c | 2 +- fs/read_write.c | 2 +- include/linux/fs.h | 33 ++++++++++++++++++++++++++++++++- include/uapi/linux/fs.h | 5 ++++- io_uring/rw.c | 8 ++++---- 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 9cdaa2faa536..631e9aa34421 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1513,7 +1513,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; @@ -1539,7 +1539,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; @@ -1591,7 +1591,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; @@ -1618,7 +1618,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 294e31edec9d..058a27a30d21 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4581,7 +4581,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 00fc429b0af0..c0a7083a62c6 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -121,6 +122,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) */ @@ -317,6 +322,7 @@ struct readahead_control; #define IOCB_SYNC (__force int) RWF_SYNC #define IOCB_NOWAIT (__force int) RWF_NOWAIT #define IOCB_APPEND (__force int) RWF_APPEND +#define IOCB_ATOMIC (__force int) RWF_ATOMIC /* non-RWF related bits - start at 16 */ #define IOCB_EVENTFD (1 << 16) @@ -351,6 +357,7 @@ struct readahead_control; { IOCB_SYNC, "SYNC" }, \ { IOCB_NOWAIT, "NOWAIT" }, \ { IOCB_APPEND, "APPEND" }, \ + { IOCB_ATOMIC, "ATOMIC"}, \ { IOCB_EVENTFD, "EVENTFD"}, \ { IOCB_DIRECT, "DIRECT" }, \ { IOCB_WRITE, "WRITE" }, \ @@ -3404,7 +3411,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; @@ -3423,6 +3431,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; @@ -3614,4 +3628,21 @@ 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) +{ + size_t len = iov_iter_count(iter); + + if (!iter_is_ubuf(iter)) + return false; + + if (!is_power_of_2(len)) + return false; + + if (!IS_ALIGNED(pos, len)) + return false; + + return true; +} + #endif /* _LINUX_FS_H */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 45e4e64fd664..191a7e88a8ab 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -329,9 +329,12 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO negation of O_APPEND */ #define RWF_NOAPPEND ((__force __kernel_rwf_t)0x00000020) +/* Atomic Write */ +#define RWF_ATOMIC ((__force __kernel_rwf_t)0x00000040) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND | RWF_NOAPPEND) + RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC) /* Pagemap ioctl */ #define PAGEMAP_SCAN _IOWR('f', 16, struct pm_scan_arg) diff --git a/io_uring/rw.c b/io_uring/rw.c index 0585ebcc9773..2ad2256d4acf 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -714,7 +714,7 @@ static bool need_complete_io(struct io_kiocb *req) S_ISBLK(file_inode(req->file)->i_mode); } -static int io_rw_init_file(struct io_kiocb *req, fmode_t mode) +static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type) { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); struct kiocb *kiocb = &rw->kiocb; @@ -729,7 +729,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; @@ -797,7 +797,7 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags) iov_iter_restore(&s->iter, &s->iter_state); iovec = NULL; } - ret = io_rw_init_file(req, FMODE_READ); + ret = io_rw_init_file(req, FMODE_READ, READ); if (unlikely(ret)) { kfree(iovec); return ret; @@ -1010,7 +1010,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) iov_iter_restore(&s->iter, &s->iter_state); iovec = NULL; } - ret = io_rw_init_file(req, FMODE_WRITE); + ret = io_rw_init_file(req, FMODE_WRITE, WRITE); if (unlikely(ret)) { kfree(iovec); return ret; From patchwork Tue Mar 26 13:38: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: 13604186 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 90DB582D67; Tue, 26 Mar 2024 13:39:57 +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=1711460399; cv=fail; b=jxTdAZj2vLkPHTG6QnX9YTFF5K1T0qf8qG2ENfjwBCMqeShM4iyR/N0ANOpa97L5Yj0saTGYkBPWGn7ziEh59rdcnGDxeXrFmEcfBA2OwkWaD8vH6QK5j5gaYPdpm9vsxuuEbf9niy9QZMgUBKZZptQtOQH/OIqFSEpPQMNJBic= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460399; c=relaxed/simple; bh=jsHc9p33HPAreiir5GCT0BSbW1c/dsvLyIdIer6Zu9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=sH05AX4M7m3ICNnoUFEJYJNENMSfcy2CKbveRpKj+GroiRhaqXzPfHZVl8l7u9/TNo4K0Mj5z8473a+CCscVKOPz1Lc2quKEQn+eG+mqC7G4E5C5KMRvpkyNyXMCLfvdyOjYl5B99lfHsVSDdmKOpqSB8CkVTquTWMCa84WSm9g= 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=acfjtXlk; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=qA/TZTcH; 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="acfjtXlk"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="qA/TZTcH" 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 42QBo6rJ026832; Tue, 26 Mar 2024 13:39:23 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=IFXxLSY+dH6Wp/TvsZw0MMxRZOJBurWqbfRz1rH17aQ=; b=acfjtXlk4g2KC+0qXaQ3hBFp0dUnVYd7ZNif12LWC1809JtJglFL3xdkLhHKsepWCzcG 77T1lRaCzQnawhK199S0LEcVKotx+lVEJGcVXUQIy+xUc4MxupxppxckYsIcwhTS1B2q StV2pYgSIoJtclKdGgX7yfJqH4VGcBCGtaTdulGcYPhe0aHkjvJDVzVQTkBw9+wuWOOK K24v1wEJJgWigCEYxYf4UC18KranN/55dizTtECdHnOhfInqJJBCvTRq1Qe+EB4cjeq3 WK4H4wpRQV2pTbOQatxuKpr5KszivSu1SXqYLJXYct4GVvxYF7jqSzCGG0QTen/fxUK4 MA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x1np2d1uc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:22 +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 42QCMRqb017553; Tue, 26 Mar 2024 13:39:21 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2040.outbound.protection.outlook.com [104.47.51.40]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nh77wtf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i6gdpUFj8zF2sagc7gnDjd7dC215dKCKXRWHjp6h0BNttwAeGaK+plI2nJZZgWzLKSzJbF8x/k03wNhIQHFIcRLl3stLkcPINdLdZU0eyjXNdcRdhtngxyv74ayz/8iRApzi2eGhUg7lCgI4FUrEYIgFN0pBDaJd3rYEhCsGTzML/lCgVPmJ3uFOljG1O1ZOTJBs7WGuZauCcjjf7vKMgoOG7yBIv/w4dno/YM4+1tvu8BRuNenKXAoMk+3T77CmIxlFg5gfHRDrrNxApKCTDRvKFboO0vh6TSarDx/0dJDK1pZ13gv9kAlZ9aQNRBNGlcGL3SXflLMfFgfO/rj0Tw== 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=IFXxLSY+dH6Wp/TvsZw0MMxRZOJBurWqbfRz1rH17aQ=; b=lMUERJYxwj2G0e+bA8HDITPUyrI5P85uZDewRsavjlcFr/saxOrmwgkD64tNPhWdWGf8vPvheJGY/01kX8OQmcWNpzTyxMKjYlvBRvVCEspaCGIn0IbQ6YFyZRIZ0nQ59OKTQTIv45r/RX5vtr+DXzddes7zwcTjvM1fUYDBiastJMPZqLTnuaLbOKiGBqnpKNmu0r6hppBPDGrxzGXfCME/63Xl40FsSehiQY6/LUZH2K5rSwRCUNiYbUB3PSSVCMhqBvrvkzYls+cTZ5IwKI/MlV5oquD7nbCS+QNRX7vXdjNBn974DhB5TEtbg97qRR59Q+nenhck0/9edNSy2Q== 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=IFXxLSY+dH6Wp/TvsZw0MMxRZOJBurWqbfRz1rH17aQ=; b=qA/TZTcHnqoakDKNZDpDmsCsTppePALS5rFdaad4A3brzTf/PCwjrnWWv+ltSvNWbrRQxETg6rLKGJiI5lZ/NJCmMJrRnpKTKcZDHK4rpdA99Af+Lbr3qYppJxCSLrokzfWpe7TfnWUjn27cLgWIAY7zAv0V4IAxR4qtDCL99Dg= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SN7PR10MB6666.namprd10.prod.outlook.com (2603:10b6:806:298::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Tue, 26 Mar 2024 13:39:17 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:17 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, Prasad Singamsetty , John Garry Subject: [PATCH v6 04/10] fs: Add initial atomic write support info to statx Date: Tue, 26 Mar 2024 13:38:07 +0000 Message-Id: <20240326133813.3224593-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P123CA0465.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1aa::20) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SN7PR10MB6666:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6/SD5f93uOKJNX1iLL6QB1/W24ZToeib9KHKYmFvJhUc+3IFwO0wd067K3UXcV2HwwtRdRtH0FA44GA8TXhsNwxVLS8eliISdTYAvzs6+9MHx7Q16nn5ULzEr8v9g6a+A52xEUbAmomOcGtosTmyF7eGvLLO70aewTDEHyLZz99zeyHHp437GbGa/diUpDmB6bWVsTyNhKndODSZFPF2szNmCobyP6Ii/vPr/GG2Al6Fl9WBRnIL3RzpkpQeN/2Fy8qCGYRAMm+4PLxRlZtZ1G+9PhM+mAa/AvC8DVBKuE0UeeahtUmcPtQriq6C6OJAbDMg87PvbnnMIJSVwjDQYE2A0IOaiGvV5Lw4Frwmq8BBjCCuqtLFxJOiqn4Lm2+1G3PviJAsdoKKl0HcQ/P0ini4zQBF1iZTnFmfEnOHtyIRczf1BZdVVTqMp9dRSNA5ofCYVu+daDoT+f4JMjaM7szOnn/JHbkxJ5J1PfHPOdOCriEVy//d7cI8deqWkx95jeOmI/NCL2ar8ZG8l0QgsQtyMttD8jwj2OE1vpJk27q1HG0zJXKlEsdQTPSGcqGq5M3dWwbWcP8e+dgKbJwW3J7bVtqkUkKbliizIqpuHDwm2/XUSKz3U6vRW4xzOxXve+gpYJARQJWy8+KCFc+pW4Hvq2F98O66rv3MmZEXYWRgafwHh5LvBWyN7rwnhx9nqEHSJXjDXnMdTxnDPfLC8A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015)(7416005)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4f3EjVzohTxrWzr05J9mpDo/nNua/RTdJIkRvaa30mQ0y3FJTVz7UDQQMEsYZ25E5d8SDFhtebCEMo+qcQPcjmjjnsryllb8J7hNXOg3OiFgrfLYWq4FTwsvjWhLaCYZrS8j8lGbXkdzMEW+0DAFjg/tik20VN3EQnsLM0OgjGzB7O9ILyHUgqsGNApdKzKX72uORdkyZiaJGQlzgCV/srX8r2asP4MwrPkJXWjxRQUcExN1QXA73IetnYB4elzvqLD6TQCupAvfGl3tncot1+QZ6rL3erCMVXLALaB29scSPfKWmZ8Gy85HOqKcl/C1j130+RcbiYgj8xtclFS0UupkNra1qeSZ6ib4pjTRDTcBCwZ1IVq1GL2g2jXm/8OefkWnB2ZXy0PYBhYNDzbszHQjISmh0WqjO8rjD1n3g513dnMkyAdaUopAG0cRFpgb2NS9yeUc9RUym+PtmQf7coJMKee6NJfSh0/TBVuqrertTedsezEceFiULi7bDJZu2jEkLBBL2KQOBiyg98cWfPSdYqEeRtHsxYlS2mqJQG3Dcq6gXUL28AcDobETAVhUQFuHAMDVOEQ/bL61R9guvjg688qDPa3thIbyuoZPtUlD79M7wBrCXXDSlG6/P3+UhW3R2A7zonASKHe1p33+CBZL0gBOnjjJerq7Vi68qJeWOjEfb3q6GC8hC0TRk056/87eNR8WB0T3/WjcliNmNFEb2eqx6122cLCCdYMemd8KMWMxueD52TnT6i/azGGVTUZ3RR45yZB3mrfxOkEDip58t7XFOaTe8iKj/NkTLLWLbttgaQEZNi82GuXSa6P19JHz6tQGTihryVHZ8zrpxLUl7WGPGUyA5iG1mEAaSr9zDXdEqV3SamMVShGmLsJmTGecwWIcF38XDio5M3x+ZO7n5yDdiQe1eBjKOkbNU2AQmxITc/iJ9SuMx0Mfa6Ld2V+cY2mb4z8E+IZ+SGnJUMo/jHLkFLEttOF8EQr/YQ/b7Dwse0aYwR6c3Vpk0l1B11rHi/T76KWRk+tZY+xG7fJ0SI98lmz5B97+xnRYYjlhLkTPMV98hJXRzokfAsO2RrlavMMTcOkqJ5BfTOIcIX4XCfuR/GAlraAerjiTIYswOuSMWvJjIQe5PY5gu5/zFg5hb4YRjtFdc2WXlH6DyhOWfgL2tWo4ur8/r1xTX/FDGL2uri7ACOEiY1DY1aFpzRKsXIVTcpC/LZiHsHTIZ2ccH1xgzHgnFZcLO1WvIKUZu/UdaYsIvgF9AFTzjk0hOJx2d/JMpjRyheMX1DMGSpZS851nC/KzeIgwJyDiqaVP/IuKVvsnq2LHv1BZ2gxuJm2nqcKCFdhC1rGH2fhbX65vOViGQzoKGEiZqIGA8IrcPyPgoX6QprZQnYPAnP2k9Xvtt5ueml3opWNSe/pcFyA6HlOkxY/cyA+DBCQ2gG0+4D5XMHGetJOSm2OeA0VbsKA/eR6WplH+0O8J5w65gEFJNBLFyW5YFpcZT6IL7tMn4EDVCYPKg0RtsU1kGBqWq0SBaKfEs0fH/32YG7Ux8eUk+8a73hQkPt8AHgx7dOH0dZsFfXMXVyxBJCZyZ8reANlnjpxSFRwCqGJLOnxedw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: xoforwYZla8rYpZCVsLod9x36n4XBM3E9/UppDCyqC8ncbXXM9uYPJ3l9PP2fVcgpX+Cv63VmGz9ACce46ribz26UGjeUmj5SgPUBfsCyFLqUl4RaH6LzDmvvajEAvbszjB7KKrGHQdvhSqKBmDED68Ch3+SYrP0tsTDl9IGsDq44MEltFe24IsPLyzC5/aPpBOiVMGI7oRlB30rT1Y7iImb8DfVNZamLl9e6AL+ypsLzhUD7WiAtzaVOungMqQMlsJg5WgRmE7h2z188ZRqdou3ud+fP3ThxtisMZFfSudBcj28xKGnDn/COz7+At03/H+YrXw/33MnB0wsqm3RtkFIpILjlyRFumBTyoVszT9Q+Y6QMA11GS33bBZhWzqBMxHXNqEvXMtYLOCg8Y+T3LuyTpuU7zrBh93N8Y9ALhaq5cOoSXRK4DTKVWl/92hLfIvipj7qH8lNcDydwwlFDq726A9tZ+TaE8qQ7vbzcT/vSgMma7tv8wpeRkOhbiH4CYEIhh/AEusiBxje5SImQPiNDmn8p7KruxPshRvpwP9n/EdNJSrFNlMm8PtpkljjzSn1wjFRhI2C6S0U0zfPObQwdTV/laoOnp+BRkbpDoI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 16724b96-3a5f-4d28-de69-08dc4d9a21d7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:16.9607 (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: DMKFtduwvZ2Hk+rmKeLl6HyQ4BWtjXB3+WuB1m2U9iYMZrhmefBLUAgUteaEseJtmLronMjd8UjttuIHFPGMiQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR10MB6666 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: Whb6ArGNl-0zIrqSjJBXOCYnd7Dtz-ty X-Proofpoint-ORIG-GUID: Whb6ArGNl-0zIrqSjJBXOCYnd7Dtz-ty 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 c0a7083a62c6..6ebefb079740 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3241,6 +3241,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..319ef4afb89e 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 __spare2[1]; + /* 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 Tue Mar 26 13:38: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: 13604187 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 0A0741272CF; Tue, 26 Mar 2024 13:40:06 +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=1711460408; cv=fail; b=Mk4KmiG9QIrkj+TdJk72TuejKzNWJJNI0Urqq8IJV/gOL4wquE8CoJgIXWOgchRzjoFsdSNjU2GLj1VyCFx2X3OLmGRg4cv3JkFV3gHBwm487z63MAx3kgYP1jyfz866YsxTTTmS7WrwjCOL1K11vow5MdNpElHbILApGbs8Gfc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460408; c=relaxed/simple; bh=HjfnezAHn9RxDU2UOEkwlhLrVy2rB++8Il/EAmBotic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=YyKA70xvnDG7lI/Z9lMqaKF4rulPXNGD7QR4CUzWwFVSinV3Ot7p61NXQUk8QCozQjnBaEBTeC/zWxg1IDYjnbWJWkRb8Zk8Luu9Z+eWhKQSblHZS2C2Wedid155+5WqL8INKrasfMaQZ0Bafr80AMGbfcUbAOE/rFkBOss6KfU= 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=ZmIDVcRK; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=T2XAel6Q; 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="ZmIDVcRK"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="T2XAel6Q" 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 42QBnf8U005487; Tue, 26 Mar 2024 13:39:26 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=04dgZaUgnUSJOVKkaIMbfFyxv3q9iwm7mAseByauNjI=; b=ZmIDVcRKpV9/ykAV/BPIvSykwF1AiElWZ/Su19+AbtvkPynaelDsMEkv+cDzvBcbN24/ 3HSFRFQ6lrT7Cx6LhBha9hEMVFY6t/5aDUw+StlSw6U9fr9mmyDuupSjvFkzPVNa65FA 89/9+GiPGaFvDqIb5Mj+wSx6TDGwTskYlqy/zcJw9ZmLUxjmE+qxc6ePGHKIEtx74FPM LTdiCcWZoufaENxYTInOVNcecFMN61teUEqFlhUFIOqktyZWKarnAiZ9NS8e6V2hMsY/ izBhhO8uZO6D8i0fVk49nMfNqr12XM5+EbCO33d3gqW0VQWKThPDUumLsEUAYqBkjEJ9 9w== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x2s9gufjm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:25 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42QCMTOW013260; Tue, 26 Mar 2024 13:39:24 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nhd8unv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DD4WATvnp+O72sx7CHBQeKN6ilxlQUL7VlFk9blOmGRYNkqnEhmDRpHkSOB5mUUtBC7TvDofKByCeeE1Gfkt1v+RpR4WLrE1XsiBP3djUTToUaukBTtkce/8FI4Ro0PH5xCoUtvRnhmltOpygzKqrM5B4DAr4vyT7Qax26cDW1Ozi9vmkeOtwO2r4sA8O/pQGVbF9oMD/hSBJ7qEdCK8EqSHySmem92KiRBDvkk0shY1BjqkmgDT2hVO6tLbeo6PH32d/IJk+XLY0fiovyW+FmKbyx+D6jYCjTxN77Eemx8Ks20doE0GP0Ff/uAE55cVBGcDMAcZGSbYc/Ay9NO7FA== 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=04dgZaUgnUSJOVKkaIMbfFyxv3q9iwm7mAseByauNjI=; b=St5o+63iNwSobTF1minhiFDoEViqMDgsdGSpXKeSAuCCdqMGSb7sfg90fu2MvgDTAMopo+y/pn3AFkUweD/o6t9p5iL82Tejsb8zS7su/6YB7P9Ic+tKIVG99yKMvmnD6MuLShIGqGD5l9BFhCbPfRtqnE+qxtlBQhzMMMDIiajP6eHWUYLngQo1Kinc/TyXh+1EdK6JgrWAvojKepAEn8fXFUQOASa9x456vD98zfp58uoD65GuGQVzHZC/qPEigjegtRklOwh/MBPniTAvnfVIDtq+wUzHDbkyHwSgWtIz3QnQk/FUE5dMriNt8ZcvAUcFct02fglekkG8rl0SYA== 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=04dgZaUgnUSJOVKkaIMbfFyxv3q9iwm7mAseByauNjI=; b=T2XAel6QzXGLnX+ZWE85Hzm1lvokYBHpOqNR0BTQ9FEIzgGpeZBvWdMBju4fbrqLyaoEAiqenqCXnXgUVdRFQfdt9IIlbWVs7/nlnFVSfTUGvEUYDHhq4RTReJP9Gm2iKaWYULjDnZB35/zcbG9VcZIIgt2LhkxW++nC6o1VLCM= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB4749.namprd10.prod.outlook.com (2603:10b6:a03:2da::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Tue, 26 Mar 2024 13:39:21 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:20 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, John Garry , Himanshu Madhani Subject: [PATCH v6 05/10] block: Add core atomic write support Date: Tue, 26 Mar 2024 13:38:08 +0000 Message-Id: <20240326133813.3224593-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P265CA0112.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c3::15) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB4749:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U4BBeVnCQsDCj2cbKUoi14PqbJ4+WyBMOnkGTXJdVJlMMqBBGJ/dHYezOV+n9tgn92T+EG/bkREAzGSkzb/JA35/s3Mh4L/QmREVZMNwiiHdY/YlALfcplgZZKqvvJaF84n3B6UbncP9HIV4yL6MLUrdL7Y8hQUVTpkZ6jY/BqLjREXv8OaA6Vz6haMPTK8fWyxJN5nhe6GEKZQtmynvU86YcX7w3FlaG/GUqoBXmqszKqTLpD1RqI6wslIaEIxGCDKqAsJtoM4hrt6jbAVSDpZe/pilQDs0cGxg877yi/TkEA6m1q+KJ+c0q0pB3ohTxnFdVnrsB36RE0o98dqiJxkciiElQOwN7EcaEAKlhk9lqPEfwp2RvMS6FWBuWXiU3QIzvNi09jxEUVGM2NT3GuzIwgee4PxHx0AF+BKHm3krXdNHYRAsLqQDEjW58NpzByA/xx62eijis363XVT8G9eqc1m8/cdGU+JukV+QvR0BFvlXdJiJwlfZp8Ajp1aHOTfcBHtl/yQAQ9LufIVOnJ9fSl29oGRAUmI3EffLZd7Ug2uPDjtMIRc6q//MT3cbE1J53lmlcED3rG6bgsI0z90Trt2nnmsAAQWwBHHO+coqYoTxCl4ahnz5xewlpE574KsolIfqRGLMWDB05wZCMeVM4LQL4e5BXDfqbZNgsIYWTV4RgBJTwgj2C72HUPLGPxpbKPKG8vKCZ9twtaThcQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(7416005)(1800799015)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EEliE7LDv8vNgE+kIU7iaTRhy4PK46eK+7apHWLrUeVEeoqkB96/M8fKY83QemLlZRCNL3HcsKyPpwX1biT1QDyLEFzy+jLDsBhucnneQYe8JRyRDZS99Yj/bps187JVB6zCmVPGy22uhYV6gdzFDpeH9ROIV+mKNwGSRp2Ff4SyUSQDzU8C9HqwGGC+f3VDVa+SrItwz3a8SpkGyzHZ9WUXEA4XdIaDn9LfVszwjWy5pFjjO0G1ruLvwY+4ZNPJEbJW42uEfhvqDZ9oKkpMUnKUwmxkUuKheXrFNJDHhAAj73gIMD0vSVmcFNCcYyvC10vVj39lIu/mxt86vTzFZEZQmIu6B/a+t/Mq5B9dlUf2KGJJnX4YXwcm55E++rps22ZYgfc2Ztwg1zkqVS4iwvallv2S6rJeyZ9Xlueq3Ls3PfZSK6kLOKYY9Xk5TPXelVKhQ6yXFWyTYmVKAhMl1Z8NRHuckDMRftRl32FVkLsas+2YYgLkdS74fjkI0VuWZT0XEs5nZkS57FK0ouD5IezxXVwgK4TR9zghAZcNNB5BzlTzXGuCvhAwmfQK1tBrhq1gBhjhNUTpB9oU7iq4rnb2cFYpiU0hhnavAv7030oOLFkz06EF3EbW10uCxvl/B4FmlVuLEMdP0fShSPnDjIcnODgdOOw/OU7KFC9j+eIe15Jh29pC3io26HTfLCa+JojXWrDE/8aUWmb7OnxPSkdHDHEclir33q7GkvK+s4pMdnWfBoYd9N5pvqEWPH6DS8pDa9zHe/VDxi/wBhPU0nuWEZeUv6tmo02gao+DQFQVhnNPLRQ4kEfmQj9CENMwhgF8A6TVK1M9RZ9rh/6JBz4CUcWGhDjqWZ6LmN93bB5HXGygBVB58CEFURWrTHL7PyunI7OKmXBEpR/b5OUcdi7ccUtlz5dFatWuhSKy4z9TbveSb843SVyuwPqkuEy0ZojmFQgY085NZxn/V+smDgu7rISWoqdKltH7ArxibzNpsnRzYNbQtw84+lVcenctsQmSugGEvLR4z5q27tIrEAQo4baWgTFjnB3ntRorNCbDcQ3esqdOmd0tNXGINZDQOYmA1/2jdy1Y8xSEjits/qi4HfexOjUv6GiiZcpcjg7KjzK4WhIaiXeG9z2BE1BnSz9ZIoutJ9mw3nGaZsmHFcgnS+xLBEGinwju8Vqn7EyxN7YmDjMisK3OXN9WWW6m4uNIpP+l5XxCL8a31RGJ1Yqkl3Gse34mo5fRexb5hqO9rRM/Ujkj9Mb3a0rQODPwhpYPVGistJE8h3MsVvYsS0LPAcrtNJw6qvJ3TlQEZezKCAIghRW5Diet181PPmspStWPTl0B68E73PGV74LVMZk1PuGooblPRx6c1ZboDHNbmDUWD/3KuQ0ij5bRN0ypS+8Cr2pGYB99ccxdhHa/6LLG3KIavrpvztxng0WC23ZLITVDhSdmFjP49BmjJ4JOAYBveKLKgNKiOg+Dywfu1jcZP/C50UD7R8xaYLAbHaGNcegp3ehqddS7nrLjN4Tnl7yjqAnepd1odxix4e9ORDnU2oy+lmoK0x9ZRR85NbmWkQYmu4IsSnT2UZewyIxCY/gEUbw2djE6kQ9AlQWclA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: yC9O0HgYFLXSpVN4U5p3aIM0Qe39mgoJoydGxtKSm5/HtRmh+zDdc/xFTQcxVUGGuOGqlmXwwjwx54u8Q/DF8i+LyttgNj9SrszvT87jZOjurihV33fafRZ7JVYHnurt6fHGyUFd1AHw2g0c9sLDyhI8Z1PY7dGaedkdTfDkSc+FlJPXQy6R4Aemk3aMhojjokRA4E6mv+zhzsVNpM9+BcVZjabAFsrtdHo8kOCN6w3lRwjyNyTzghK5GQuH55P+EIQCN+TghJvNGN+prPB7L/cBKwNZx25dJpCVTPeUu1t6RA/V5H/C4f1PicZaBcyFbfwwCZmSvx0BKE6DPdQQfQbQT+OZwrBYOSiPouZbSCOjzYv3SDsVgEIOCmEbnsqxqzxguL21ZMuHeaWjbB2VhSy3fCp2ESZfbm2miliu5hrYd2Y5AXfrWGTesR9CeVtoiIL/B4ErWMpAbZA60AgFUqYWzUdjfZZmNdEv+FSRT8JPQvsiynT94YE7zbmMYvJ+6tN3zmJOxZXG4pp6gfh8OzLfW8nahSoB4n61in7vY8buxQdk9tpM/DJC+XXv07avPSjnyIlitkJpKrLiVvHLhaOoKnpvqI36dtFxtu2GGAI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17853eef-187c-40e5-30a5-08dc4d9a2400 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:20.6986 (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: CFbNpRQjxYOjXCrYgbfrjUJ+ci/w8NUvAS34N0DcZD2Y7hjWiZOY8nCnM2JeV1Nm4c6jstcf3xeOnfywHIDWDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4749 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: cuTgvIPuBNfij5IGwlOsdi_auJtZl2YE X-Proofpoint-ORIG-GUID: cuTgvIPuBNfij5IGwlOsdi_auJtZl2YE Add atomic write support, as follows: - add helper functions to get request_queue atomic write limits - report request_queue atomic write support limits to sysfs and update Doc - support to safely merge atomic writes - deal with splitting atomic writes - misc helper functions - add a per-request atomic write flag New request_queue limits are added, as follows: - atomic_write_hw_max is set by the block driver and is the maximum length of an atomic write which the device may support. It is not necessarily a power-of-2. - atomic_write_max_sectors is derived from atomic_write_hw_max_sectors and max_hw_sectors. It is always a power-of-2. Atomic writes may be merged, and atomic_write_max_sectors would be the limit on a merged atomic write request size. This value is not capped at max_sectors, as the value in max_sectors can be controlled from userspace, and it would only cause trouble if userspace could limit atomic_write_unit_max_bytes and the other atomic write limits. - atomic_write_hw_unit_{min,max} are set by the block driver and are the min/max length of an atomic write unit which the device may support. They both must be a power-of-2. Typically atomic_write_hw_unit_max will hold the same value as atomic_write_hw_max. - atomic_write_unit_{min,max} are derived from atomic_write_hw_unit_{min,max}, max_hw_sectors, and block core limits. Both min and max values must be a power-of-2. - atomic_write_hw_boundary is set by the block driver. If non-zero, it indicates an LBA space boundary at which an atomic write straddles no longer is atomically executed by the disk. The value must be a power-of-2. Note that it would be acceptable to enforce a rule that atomic_write_hw_boundary_sectors is a multiple of atomic_write_hw_unit_max, but the resultant code would be more complicated. All atomic writes limits are by default set 0 to indicate no atomic write support. Even though it is assumed by Linux that a logical block can always be atomically written, we ignore this as it is not of particular interest. Stacked devices are just not supported either for now. An atomic write must always be submitted to the block driver as part of a single request. As such, only a single BIO must be submitted to the block layer for an atomic write. When a single atomic write BIO is submitted, it cannot be split. As such, atomic_write_unit_{max, min}_bytes are limited by the maximum guaranteed BIO size which will not be required to be split. This max size is calculated by request_queue max segments and the number of bvecs a BIO can fit, BIO_MAX_VECS. Currently we rely on userspace issuing a write with iovcnt=1 for pwritev2() - as such, we can rely on each segment containing PAGE_SIZE of data, apart from the first+last, which each can fit logical block size of data. The first+last will be LBS length/aligned as we rely on direct IO alignment rules also. New sysfs files are added to report the following atomic write limits: - atomic_write_unit_max_bytes - same as atomic_write_unit_max_sectors in bytes - atomic_write_unit_min_bytes - same as atomic_write_unit_min_sectors in bytes - atomic_write_boundary_bytes - same as atomic_write_hw_boundary_sectors in bytes - atomic_write_max_bytes - same as atomic_write_max_sectors in bytes Atomic writes may only be merged with other atomic writes and only under the following conditions: - total resultant request length <= atomic_write_max_bytes - the merged write does not straddle a boundary Helper function bdev_can_atomic_write() is added to indicate whether atomic writes may be issued to a bdev. If a bdev is a partition, the partition start must be aligned with both atomic_write_unit_min_sectors and atomic_write_hw_boundary_sectors. FSes will rely on the block layer to validate that an atomic write BIO submitted will be of valid size, so add blk_validate_atomic_write_op_size() for this purpose. Userspace expects an atomic write which is of invalid size to be rejected with -EINVAL, so add BLK_STS_INVAL for this. Also use BLK_STS_INVAL for when a BIO needs to be split, as this should mean an invalid size BIO. Flag REQ_ATOMIC is used for indicating an atomic write. Co-developed-by: Himanshu Madhani Signed-off-by: Himanshu Madhani Signed-off-by: John Garry --- Documentation/ABI/stable/sysfs-block | 52 +++++++++++++ block/blk-core.c | 19 +++++ block/blk-merge.c | 95 ++++++++++++++++++++++- block/blk-settings.c | 109 +++++++++++++++++++++++++++ block/blk-sysfs.c | 33 ++++++++ block/blk.h | 3 + include/linux/blk_types.h | 8 +- include/linux/blkdev.h | 61 +++++++++++++++ 8 files changed, 378 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-core.c b/block/blk-core.c index a16b5abdbbf5..de868c91a295 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -174,6 +174,8 @@ static const struct { /* Command duration limit device-side timeout */ [BLK_STS_DURATION_LIMIT] = { -ETIME, "duration limit exceeded" }, + [BLK_STS_INVAL] = { -EINVAL, "invalid" }, + /* everything else not covered above: */ [BLK_STS_IOERR] = { -EIO, "I/O" }, }; @@ -729,6 +731,18 @@ void submit_bio_noacct_nocheck(struct bio *bio) __submit_bio_noacct(bio); } +static blk_status_t blk_validate_atomic_write_op_size(struct request_queue *q, + struct bio *bio) +{ + if (bio->bi_iter.bi_size > queue_atomic_write_unit_max_bytes(q)) + return BLK_STS_INVAL; + + if (bio->bi_iter.bi_size % queue_atomic_write_unit_min_bytes(q)) + return BLK_STS_INVAL; + + return BLK_STS_OK; +} + /** * submit_bio_noacct - re-submit a bio to the block device layer for I/O * @bio: The bio describing the location in memory and on the device. @@ -786,6 +800,11 @@ void submit_bio_noacct(struct bio *bio) switch (bio_op(bio)) { case REQ_OP_READ: case REQ_OP_WRITE: + if (bio->bi_opf & REQ_ATOMIC) { + status = blk_validate_atomic_write_op_size(q, bio); + if (status != BLK_STS_OK) + goto end_io; + } break; case REQ_OP_FLUSH: /* diff --git a/block/blk-merge.c b/block/blk-merge.c index 6f9d9ca7922b..34a68e131168 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_INVAL; + bio_endio(bio); + return ERR_PTR(-EINVAL); + } /* * We can't sanely support splitting for a REQ_NOWAIT bio. End it * with EAGAIN if splitting is required and return an error pointer. @@ -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. @@ -818,6 +905,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 @@ -949,6 +1039,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 3c7d8d638ab5..98d6c2f59ccf 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -97,6 +97,41 @@ static int blk_validate_zoned_limits(struct queue_limits *lim) return 0; } +/* + * Returns max guaranteed bytes which we can fit in a bio. + * + * 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(struct queue_limits *limits) +{ + unsigned int max_segments = min(BIO_MAX_VECS, limits->max_segments); + unsigned int length; + + length = min(max_segments, 2) * limits->logical_block_size; + if (max_segments > 2) + length += (max_segments - 2) * PAGE_SIZE; + + return length; +} + +static void blk_atomic_writes_update_limits(struct queue_limits *limits) +{ + unsigned int unit_limit = min(limits->max_hw_sectors << SECTOR_SHIFT, + blk_queue_max_guaranteed_bio(limits)); + + unit_limit = rounddown_pow_of_two(unit_limit); + + limits->atomic_write_max_sectors = + min(limits->atomic_write_hw_max >> SECTOR_SHIFT, + limits->max_hw_sectors); + limits->atomic_write_unit_min = + min(limits->atomic_write_hw_unit_min, unit_limit); + limits->atomic_write_unit_max = + min(limits->atomic_write_hw_unit_max, unit_limit); +} + /* * Check that the limits in lim are valid, initialize defaults for unset * values, and cap values based on others where needed. @@ -221,6 +256,23 @@ static int blk_validate_limits(struct queue_limits *lim) lim->misaligned = 0; } + /* + * The atomic write boundary size just needs to be a multiple of + * unit_max (and not necessarily a power-of-2), so this following check + * could be relaxed in future. + * Furthermore, if needed, unit_max could be reduced so that the + * boundary size was compliant (with a !power-of-2 boundary). + */ + if (lim->atomic_write_hw_boundary && + !is_power_of_2(lim->atomic_write_hw_boundary)) { + + lim->atomic_write_hw_max = 0; + lim->atomic_write_hw_boundary = 0; + lim->atomic_write_hw_unit_min = 0; + lim->atomic_write_hw_unit_max = 0; + } + blk_atomic_writes_update_limits(lim); + return blk_validate_zoned_limits(lim); } @@ -344,6 +396,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(limits); + if (!q->disk) return; q->disk->bdi->io_pages = max_sectors >> (PAGE_SHIFT - 9); @@ -384,6 +438,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 = bytes; + blk_atomic_writes_update_limits(&q->limits); +} +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 = bytes; +} +EXPORT_SYMBOL(blk_queue_atomic_write_boundary_bytes); + +/** + * blk_queue_atomic_write_unit_min_bytes - smallest unit that can be written + * atomically to the device. + * @q: the request queue for the device + * @bytes: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_min_bytes(struct request_queue *q, + unsigned int bytes) +{ + q->limits.atomic_write_hw_unit_min = bytes; + blk_atomic_writes_update_limits(&q->limits); +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_min_bytes); + +/* + * blk_queue_atomic_write_unit_max_bytes - largest unit that can be written + * atomically to the device. + * @q: the request queue for the device + * @bytes: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_max_bytes(struct request_queue *q, + unsigned int bytes) +{ + q->limits.atomic_write_hw_unit_max = bytes; + blk_atomic_writes_update_limits(&q->limits); +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_max_bytes); + /** * 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 8c8f69d8ba48..e2ff824ce02f 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -118,6 +118,30 @@ static ssize_t queue_max_discard_segments_show(struct request_queue *q, return queue_var_show(queue_max_discard_segments(q), page); } +static ssize_t queue_atomic_write_max_bytes_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_max_bytes(q), page); +} + +static ssize_t queue_atomic_write_boundary_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_boundary_bytes(q), page); +} + +static ssize_t queue_atomic_write_unit_min_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_min_bytes(q), page); +} + +static ssize_t queue_atomic_write_unit_max_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_max_bytes(q), page); +} + static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) { return queue_var_show(q->limits.max_integrity_segments, page); @@ -495,6 +519,11 @@ QUEUE_RO_ENTRY(queue_discard_max_hw, "discard_max_hw_bytes"); QUEUE_RW_ENTRY(queue_discard_max, "discard_max_bytes"); QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); +QUEUE_RO_ENTRY(queue_atomic_write_max_bytes, "atomic_write_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_boundary, "atomic_write_boundary_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_max, "atomic_write_unit_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_min, "atomic_write_unit_min_bytes"); + QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); @@ -622,6 +651,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 dc2fa6f88adc..5e49c14525df 100644 --- a/block/blk.h +++ b/block/blk.h @@ -192,6 +192,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 cb1526ec44b5..b7d35ead4d1b 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -179,6 +179,11 @@ typedef u16 blk_short_t; */ #define BLK_STS_DURATION_LIMIT ((__force blk_status_t)18) +/* + * Invalid size or alignment. + */ +#define BLK_STS_INVAL ((__force blk_status_t)19) + /** * blk_path_error - returns true if error may be path related * @error: status the request was completed with @@ -381,7 +386,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: */ @@ -413,6 +418,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 c3e8f7cf96be..07145b0acbc8 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -300,6 +300,15 @@ struct queue_limits { unsigned int discard_alignment; unsigned int zone_write_granularity; + /* atomic write limits */ + unsigned int atomic_write_hw_max; + unsigned int atomic_write_max_sectors; + unsigned int atomic_write_hw_boundary; + unsigned int atomic_write_hw_unit_min; + unsigned int atomic_write_unit_min; + unsigned int atomic_write_hw_unit_max; + unsigned int atomic_write_unit_max; + unsigned short max_segments; unsigned short max_integrity_segments; unsigned short max_discard_segments; @@ -916,6 +925,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_boundary_bytes(struct request_queue *q, + unsigned int bytes); +void blk_queue_atomic_write_unit_max_bytes(struct request_queue *q, + unsigned int bytes); +void blk_queue_atomic_write_unit_min_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); @@ -1339,6 +1356,30 @@ static inline int queue_dma_alignment(const struct request_queue *q) return q ? q->limits.dma_alignment : 511; } +static inline unsigned int +queue_atomic_write_unit_max_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_max; +} + +static inline unsigned int +queue_atomic_write_unit_min_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_min; +} + +static inline unsigned int +queue_atomic_write_boundary_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_hw_boundary; +} + +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)); @@ -1592,6 +1633,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) + return false; + + if (bdev_is_partition(bdev)) { + sector_t bd_start_sect = bdev->bd_start_sect; + unsigned int alignment = + max(limits->atomic_write_unit_min, + limits->atomic_write_hw_boundary); + if (!IS_ALIGNED(bd_start_sect, alignment)) + return false; + } + + return true; +} + #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } #endif /* _LINUX_BLKDEV_H */ From patchwork Tue Mar 26 13:38: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: 13604185 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 B3D44823D8; Tue, 26 Mar 2024 13:39:55 +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=1711460397; cv=fail; b=Z/8emr1L6j7/pE5HAqW6W4ZpG6xCTCEdsF/daid984FLOaQhLJ5rEy/vssddGRn5sKblee1k8BCgZ+5yVVSmIeSyKkSRKRzuOD/aXkIJcbPsY7uLGNJ4r4YQgxMaF5z2CXT4hphTLdR+dDf39rXe1NxfWckJJTF76YWfnjpoi+8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460397; c=relaxed/simple; bh=3cAxuLAfQ3oCXhkW84Deid5lrqEaKr1Rlnalqs7AcxU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=FFGqAht0UtnpoeYHUr/FOR3FVup1ujEb5G/wWZtdFBXt55ZPmIm6yBcQy9xMGPoAOsZlvtBOR/OWdOjPRVsxHOI2RP8KM/nS+6kCdJjhgwin/CsW+fus7ir3DxT/9SVBRtBDQ/nXanwbLYBEM01uCaWU5utsGdT2F8RfFwvnhu4= 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=Wg1GJEBf; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=hrjZvV3z; 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="Wg1GJEBf"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="hrjZvV3z" 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 42QBnhZq020670; Tue, 26 Mar 2024 13:39:28 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=Fr54FxUWLT52JWHUXn2QR2++EZM85WeiAnL4rlrMdEQ=; b=Wg1GJEBfVYCdv3SUioF/oGMWrWyRKrFi+vJOGujUxIp/rKvBM/LHROQP+ilZeoQwDbyd m12b3UBsszyk05/bxbxw7A2X3iUeGCZPhYKlsU2Prrr+RUAOFdcLQPyy5dSIJ0q5zuwy /3r8rNv5ysa7yKllOZlPwhPN12E6VTgO5COLErklqQAuk2kgiHN1XHbu0NQIcIoJ/Sng 45a0TsrV5klz0mYdOVgeMnvlj1emvnJ08yLP9J0/HW2IZP5CzvuhP3iYkdYVv+ZViBD8 Zur0FgvfSg7ghHFwIaMCt2DW8Xrn4ahK2URHsZGdmlguAdB7E4XSHAH9owv2y+/vJX2S zw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x1np2d1us-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:28 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42QCMUlL030916; Tue, 26 Mar 2024 13:39:27 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nhd8ms1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bsEcen+8AyBrDQ3WeeCiDHDsUAVclBpgSNXHZIVvkW1xUvdEfmyVNj6NOvXNOWvqst0oU8vHF4CAmgU51WoVQGMhdVxFTfmLYV273R3gW6/f70/RX/jaqueE3OMoUypt7+XANYvhuUZTrrX6Q2DpcpL4RLVixqtGeHHymOB4qgxaRDjb7db0kO4vK3B7qdHU8BNm2Zd4+2YY/FqrrDJelofVqpNhx6MieS+XDtrFqumOZJXwhKKYfGZ4zMxH5vLvDs7RpXB16855dbjJzC3mn38ONtvzK7DPumUqJow5Q0CvZnLb0Un+A2F0pEuIoIuMOI2GdgkdZQSXmRlsdFSLTQ== 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=Fr54FxUWLT52JWHUXn2QR2++EZM85WeiAnL4rlrMdEQ=; b=KUDrY2j25XDi+Xo+BViAjV1fukQ98CV7G/Whqe8MNVQOdHRs39zjwQZpStEmxolg1BmMUi6wCkjWPAjqV6ez/igBS5Avcjn+E9jSp69b31KNdwl4LmWQWMDVWV6nuy2LdUFsYPHv2I9R/SE+rtKe9bw1c/Em+iSKyJ+COydjFByRe97CMBSs/7tAGybSKdrpEPlqSTwti9SREwzD8L4VEkmzpD00NigVIotobTqg5Z6+ofwMwlwgj7pdM693MDkKBnLhhT79SQJAkgFVDASHzy1pTrUatQa3suORZQd0G1GPmBKzVa7vG7BSMdi0JL9No1IziqKnbBn0nQMBD/ntXg== 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=Fr54FxUWLT52JWHUXn2QR2++EZM85WeiAnL4rlrMdEQ=; b=hrjZvV3zDKd45CxybEr67Kf3dcxZKkyI4iZ6TQ3kzVNX4A7kT7l3uqXHtr2wyT+armUav3FuF0FF2uzDMOrwuwRS97yvovubrFobPc96PvqxtN3/0jr3aJvWwUzHn6jCMBGAD2nwBt5p+t3qSF9ydQVB1OzFiDSpO76y/lP5qXE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB4749.namprd10.prod.outlook.com (2603:10b6:a03:2da::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Tue, 26 Mar 2024 13:39:24 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:24 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, Prasad Singamsetty , John Garry Subject: [PATCH v6 06/10] block: Add atomic write support for statx Date: Tue, 26 Mar 2024 13:38:09 +0000 Message-Id: <20240326133813.3224593-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO2P265CA0427.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a0::31) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB4749:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QeiWE8YV/Hpu0tizzf4Iyv1BwACtJo5R+YLKJCqJxACS7QnvhhU3e3X4c7jLlab6ESmbPxn9SII7cnF+ETI7pA1/spkp2cBwttu9cIwZt2Zse8VOEkiHMKuNBnWPivkHUUDRMiIpZje2Qar3NzQOqlx4GedSI4dUrGOYJIBLneO1BM87hnX4WQ+q5A9d9Y6DiFsslbHHdAK8WwiYLSDrdvltSgor8b17daqtIdS0vmyjbV86MT89gC32AVtKzJKIeGVFKNiE0yVgMq2ldDKNdiJGqKz12VoBTx9wSQdfMCgLVUtbhj3I3NZkZY9Ovc+aEnPCYwO6mfbvDOCM1URgMsJAiflcQ8F+BUv1WJf/Yy6wokVAdvPl7QEpSdSR9RNC2EmTdxEGZWm9bwh8LyojsRvwsSNzQFb+bpAjQ4p3hwPiDKSVhfFeolTE9PTJgG9SEWzcEi3VPGtSfzBVH5USxwR1EC6OZMJos3F4pC2bUOBlY8pv6qpV0KusQL+zDVbx4OT1m/spsisWYnLO1YxoAh7RmIOVrZjT34piS4go3oqLvF6QPO8h8hUkKRyQbnBQP+0OobLyq/xrdSUG+EO6maa2+zZdeoH4OJULfjB0eaQwUnuMRsLo4BpNTzHj1kJROsYDFd6zqfPc4SlmXDTgNxlIq18z28YjeQOmCoWfLrSJurCMmYxEjBryz5bZk9eunPOZe+QlfcWWc32Hr+BMfA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(7416005)(1800799015)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8feuZROfENmivh9lEuT2t1PmMCyXSr7LC99rebYy5rE4S4ZDSQObJ+iEpKDKi6NXWB3nZHFmz9jXh3Z36nKucRTWCvMCGsL3TmphYU0FwB0UDjch0pAbFxQPOjkTct1tY5cTrh31QF0P0bm2m9zBAVHqvxKNNIDiyOZsKCb1+KJBsjlspytChXe6zTP0lyb3+13xFt7uYncrWvH4f/KW728NXf9bVIA4HvRLXL4seSlypOhnTAV49N6dVhr94B4DdZLY5pmqLwFqyxVC2ShDBGvlQ8p+ttly7bhchZo8W4a1aZ7V4ZYSBITSt79bgo7lXl1QtGT/g0tppP6SqFDkQ2S/NbDDSijQR90jOlk5bGky+7NKUz9b6Q2CXeLho+YqJI1xCFxfx6q7O6jNhGuU7J6uoNe8GdVgYH9iph0u8hhTMC9jLuSyoW3tsyxnaxxDPFo9mePwn4P1QbF+Vr1lJWvvjGeUHaSBuRIyHKqhDgEVVvAkWayCd77nz5eGxnXeDRryb/yWel+3XR/6cpiT2cdUTQIiyflFxtGbB1nitGQ5RGgl+sXbI1gtT5n578UK+Xeg8AR+u/o+wwaB9S9xDbMFUmhV5H3jAQtQ7fgq8sUhOu5jEzeM3idjMMRuxyQD5f6Tkpu0aAACkdHzruMgRNPLzbIh+cylQLGweeM692TSrSIj0DbGVjlwnJBi+41gOPeuDjuYLEpwdlWUpTbepOASVdTyGFksTZ7VpWcN5z3km3cnlZG6crjGPKXMSLDEb7F4MVYU6HjI+FtxRwr0q4zdb+lo1+SINyLhBAj8ZhtcdD2NlzegtH1Ah3PGZPTvso0QVTydU07HVOkNLuIhyAHKuJCkPz0kBJt96t+/a+rV2ir30B2fiSgK10kP9UgwScMXGoT6JoRlMJP66N2wD0lZAiaz/EvMKScawhVpxna5eosoONXiGrxoUT8YLYrJNVuyMKNubLKEmumQAoEdV2AD8PuTic6jH+KBbKOSJsH9AqCU99IszXjkuoMcnufsdxl3uJgkPy53wXDqKa+dv4DwR7MRaszdGwNSWnHDpPTDyJLt68xTqDugdGquQDIo3vG3DiknfYQeGPDjEmAVKFAzg3DE/+mqJVKqtjQM7MpW5Pyxnuxpng06mlqk3RCN4FCdaNJxpcDOhDAkVBdsIPqAwxNWKQtWFEQ5vTl5+w/MzMB8d/tz+hod8+wgllUw18M53UVHFApRMY36KlD7ioNfJLOvvlqJEJjh57J3nGUpreo1GplIp73zSUGzBrZy7hDMdjje7cAB4ilJ99GF3IEFmda+lFiSLPq1tTbzTEYyZ0/FYwgNzI7TY6on0tlMoAU1LC7BPhHQyXFEUMpOZTbLDDSgBmcGp7RvX4Wa1RC5DWSGhgfK0wWMYYP84p87WKkYPfr76fNMI6TZwE/4Sveofn6Iib4trjsKG4d3+J/CcvnOzR3b3ru7GbKyd+LPP0BShiKnNzeVnCC65BAxnV4q9/EDWR20FGuM2zEsrDSyOk9BvEI9QVpMeNSHsjKkAARElu+udXSyxb9apQW4NxBH/DEXAcMfAMMONtX6yVryG1yfWVMc2PhBxiG8qIOKqDOt4i5O3ZKp2yGmqQvegQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: mcu7IA9wl9F0ouj1JrXxtibZQ/b+xwJ/6kV4BdtM7EPq95dl+PzTPM2Yjlmo4YOXLLlgRGNFsDo0eJex4kUEruliGJd8Uec0LRdU/2IoRZnlEL2vJ9yS4vT0TLBtyD5ko2niKx1BqtyiEHjex+p6vG6xdFtb1Yni3TGUDIbV0LoPbjEnj6amXOPHJtTNu0ke9kQbp185K6vxXH51hRr7g1o9NAWzfMkcHBNQKQfi+jN9Ae94F1mKNmNTDfmnxy6PhBK/mmTohishlEX3Tbm3sf5jITVxbxFluf6/VmLfGm/vl12KZJZXjgvUK4Hre1KfWd0wOYnGrIJ70ZQHHbksD9Y9Y3wI8+1uSr/LvIsLYBmBG0JZcBTbIL9DnI04KdZlr8rxu7jHatOD6qq7OIlWW1WYVW4wheaNuiA+Zdu2Vm2+hDN0pSerKT8UnfidzG+eMnjHHCUwe6KLFdal97l9y1dnIez4p2lAM3lCvCC8x5akaaPLUeAOvX0ISLhm6PYrsG4MOv9TM/3vg/a+Pc6lkJQUFeLymQBNrTN0mUuw/81s1fSkDon5VqjJ8aQGABqCDJugaBC72f6vSLU66vpfyTFtx2GkpabDbkX5aq06h2U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: db865a8f-9e54-439b-f84c-08dc4d9a2673 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:24.6118 (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: IxxdKyBQJAxMU6Fk+vgShypIBBFgkzmJz00nEfiGjx9QhDo+pqbED/bPwhXHyvgrxXPB+6kT2bY+q3wMHp+Gxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4749 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: 8YYgz4Fw3dkvOzl7EvdHNmNx5iR5wjTg X-Proofpoint-ORIG-GUID: 8YYgz4Fw3dkvOzl7EvdHNmNx5iR5wjTg 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 7a5f611c3d2e..f3dd9f3c8838 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1182,23 +1182,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 07145b0acbc8..d16b0c451b27 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1594,7 +1594,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 @@ -1612,7 +1613,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 Tue Mar 26 13:38: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: 13604190 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 0592974E03; Tue, 26 Mar 2024 13:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460470; cv=fail; b=joaIQyHKMG/xC6S8zZKPtYrS8hxriLf+xiYbvFVbnHMGvQpr75piS4RbUhZJn3Hroz73A6XKXphePqUfjVGL0H48WUBC+QBRtjxO/EzB/zi31EsvzQy+p1Bp/2gzEvhiT7Fmjyi2VKBKcAAHtEW6jYlls9A8FJJO8HYTmFsW/GQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460470; c=relaxed/simple; bh=xJuoyL3PVMUwPxMDLvExBeqFnhSyGc/ugQWKDqRVEFg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=fpLuXVacNlzdKvgrKHTQNjW0ovV2dKVRMoepy+DLCaTJKvv/0G0NX2JftayIAyn4UjIBf2Y7I69otvndOypRO/PUklQNS3il3b24jPfK8t7vWfBibddGzdvV7MIAwvnI4fnoI3YWSVqlGWiIFJ/ibexlSG0p7ML0t6POtlb0L7Y= 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=ZHoWPy2y; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=Etr9fFCX; 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="ZHoWPy2y"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="Etr9fFCX" 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 42QBnX9j005405; Tue, 26 Mar 2024 13:39:33 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=2UEAXMQrzzKW8qOpzGvlPgwNC1E5B9xoTu8Ke0cdPNM=; b=ZHoWPy2yBZrjjfQ4uiJb1F7PE9HSBUIL65prujO6Ng/a8A8EvkRF1bgJuJD9Xp9g7ID7 3eIEq8d2lkOfsF3STbijwjwvSNQLGtPdeMR8m5PG60ehSWtxxnloUDBNwaEa5UtQ9fod znarXdSL4XHDYDgDCq8xqG7XRXVV5ak/hZ0hTHpBcCVfhLCr5N1DhYli1KS6uK+eJyC4 SfifZgtafjR+pJrXMOTis1dQ6FFYHo/lBayPF5IvTgrrI0xyk0JQvDm4TqrW9eQLHwUe XEx8Ql4RZzrKCV7MqG2JHD0REm6nqzXimGalLz7dapTfquoqobmnEhT0IDdFWydJZUIZ Eg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x2s9gufjy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:32 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42QCMVdh030948; Tue, 26 Mar 2024 13:39:31 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nhd8mv2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MoogeVJ7GeWhLFS8Ai32GADkP689/eW+fftXcooMOyWadKqTtIvLF7i2lB/xvLAl7D+QriwKwvMMmVM7BkGzGuQyDVShQT7SlKcZIGoQDvBR8LYbQv88T978oiDcfNOkdPnh2B59BGDcai9RCGvKG9L95zgY6IckJX+bucC7+AXnABsmOMmDl0ztWTdHZymyqksnAo8GMm5paxnDW9WyCUNHQWlIFLpRO75Aw/oxXwldnSmLj31LozDHohCNLSqxde+G7aMN+Xs8r2xGYMku0V3zPlxgEMi5lp6Jk1wkFrjgIKHE1VsAHSPuDcNeQ9G0FhlfkrgX2h6VjsVZsQCjGQ== 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=2UEAXMQrzzKW8qOpzGvlPgwNC1E5B9xoTu8Ke0cdPNM=; b=UJeisGGLdi72CLFOTMDHcnCymvYGjho2eNOlO4zAjBHjjab/CkWhDqXrYARpqGpO0nUfuP4LP0L5HJfSywmCOI2qQOvSZMrDD/qxsjLmD+75FL4QJ1fLWqh9H20PcBam/tS5ug7hGDDSCfOjaYBtDw9NKLOPPs6Vn29tybLn88g5iQ8RXDWVvWTPLR1X6yJEH8xXhyCQ2yMcqtOhAV3RpMUPWL41FmxGLAcHfAzn8h1vST0PLWKmLdj2LVl3rpVyAVYD82pXmqhCD2dUb57PuTn8tGkdwTqP5Qz2gB+WOMW3Ut4mb/TpR1mWunrEgGy7u5Yi+9xhuUhxI+QYBXCANA== 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=2UEAXMQrzzKW8qOpzGvlPgwNC1E5B9xoTu8Ke0cdPNM=; b=Etr9fFCXvGJEkQ5uasBHRXCWzfmjw7SSWhoPqc5eJI8Sdy50HqqyH6d7yiuzZ1sLqPkbJyl8QxVpk5GGmSPMuPYnXuARisMzbai2hMSuEzngvi2W45JLtgkeCnTsWWELR3MzM7xihPDB7zYoPRED4pA3VvUFjCaKSU3dLnym5dE= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB4749.namprd10.prod.outlook.com (2603:10b6:a03:2da::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Tue, 26 Mar 2024 13:39:28 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:28 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, John Garry Subject: [PATCH v6 07/10] block: Add fops atomic write support Date: Tue, 26 Mar 2024 13:38:10 +0000 Message-Id: <20240326133813.3224593-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P302CA0042.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::14) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB4749:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wpWZFFCOGWW/xVa+7hnII0KUqvkJZZ0vgSA1Gv8ZuLt2cv+P7fYhEWxnXnAWysE5PA1uw1zHnGqGkh/i6ry2r43TfSICDD7VRAK/qIEtXwF8XO2ICrblhmPInwWBsGmtujZ5N6NP5YWm4JkgOiEuz1zGJcpHLN3x9znJvEtBci3HmBxFwLvPSy+qxy7nZYSLe3w+28ID5aSaeEpZpNVrbFk6OXXwMfOXsX4rQrb9dnq2Pd3AxC1GtFBRfDx1o1dQXTdZ4xHFYgrFwd21anxbbg72po/ORUfF84q9ydNHMrRZz8WMiolJr0godlJizQr1rMEe266z0l365hQKWlJth6hqKBTSsMINl1zuOvFVTOO2x8PTgMaaJJJgjavMerWGNpxu4p/YuW52C0XhqTp09Tbtu/8HELc8ocwdOU88/W4IgsDRCzdXSeRz532XiSDjq47u8D9IoQA5pp6Cd6SYTt2AFWslECQCZFvisuDlZir/iwpkQpByDL80x+V/QUQovZEWmRM4lprcjgsHQe7Xa0/IqsT1fzzCSGFJziw+zNFlsyv9EP8coy+z4vw2g4BQWm2iG/GW4rJvnJX3gcGm/hqgVftllG2YYyYuhU2XdT6V69xtSO4rHR7DLEVCnOS6EsBCuP+4eK294m6nk3Yc2IXF1WHM3fIDUQrsyBA/yDkLQ2zLV10CXxj7HtVGPfbRoYPoMhyg9Jg9etnUFZ3QFw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(7416005)(1800799015)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ICBqZWwzK3jCpFaWezpYMmApGUNe4xYT9m2zIAiS7XLk2q1Ek5HU46XELnLBqdBCABw/vv+sna6dInhbirBYAS4x7wOrdgugs9n06AFiSS6GV8ykuUa9JWeHAraYWwS01JCCXbLmamdMQzTWwyUHvGTvV4BOVNb1rAK1KyckV2Lv0sGIC+N1EVz7E3+ilWTLAgn+5jzmYp6g20HimO4POE9V9EjA+ilsMqyg53tjZ4ZPNo+6YiBcE7YlAJ7xGvixAb0ttP4RAj69EgwdRrmXyAmOEVl1B4vF6MFO6XVYigVz0/hKw3Csebh2kfoj7F93mfaV8pIZstoVXz6PFsEalkZ9sxjUXD3H1ZJzFFrZjklmD4SfwiHIJV9VZIGnw7AxEJd5Ac0UssRQEdLnMMmr1iIO4U47qw3ckRMA7hsZcYD6jDuQz6lC23jdk/ehjq1egjNVtOB4vDpkQ3GZCbCtEtof/cM0VQ6X9Umbp9bNcgJjSDn9pnFqCwwb5LdD7IS9RxHLbySxoxihqA2X7XvXlx1PBhzmwFzor9sb8+XOuFy2DiI/bFma3oq8zbZYyfIhX5Ea5bkh4AD7w8951vM5bo9qz58fBlwbvdIxcAdtlYNeLkD2VtDxnOe7K3YDWbeUEy3hg6xAULmw4hJAKe+sOU/U22AZVCAVG9FtpQaepCtNL34xS+CoRwhpvQ7Y3OXmdluE0zwZdCQSytyKXrFPSXXlwyhq0oYdYWqnDsxS/m9c6FQmN84f+PipJ5OBUHRD12JaTtNzuaAQcfPc8UXtf79gpPau7D7dHvnQm87C91l3YKpEY1akfoBudrS7+OhGwJxoUwcuohX3XkNSL/4tyScN35b4azGnCFH6yF/ZFIl8riKYmcbG3YrggGCcntxvLuFbw9kTdCwkk7ZFBBZxSqw05poo7UYVGqwfrPPyP+1Y2Zaum1F/terKODv5Rv0D5PV95z/H8ObWML/ubPG5FsxXpMU65PWluJZh7flARWm5YeE5o7WfmACEohOYCQ9uopuVhPtKVzW0vzStWmqtHVQZKjdSYP6r+lyuXV4tWAzLFpxOofKQ/9SkjqT6+fMBugPKThGm4AlctzO4vQ3PJgmyow6WjGwCW2nAplZiv4OPdddIYga2iRCOjDk1oWqmzqbOAGxQEytfZb1DxYKojzHuVQp9j3xrBRbZt7183vPfa2lzzEA6VrSzRnSm6UOpWTCG+awQOvH08cH1pXWJz9UUzEWVwG1167469MUyZgC8WerLbq3grHVVq2jCXmKBPdRnG11Mak3kh9xN/pDS84LdxJ3kDPCdqXoGv1cVJ/bhYpZ4kBzFgq+IR966suRuu/KWcVbvPr9t+FUUXOat3GmXoAtPkhAJY/r4Lk1kwF0UoLJA8HTWHzdly3QvAOZHnjoBLUqSZcg6MFc4ArkKqBzWqVyEK/gRJLEQjipABVfwiSvBq974NJ2HEDqgFm3d9lt+0IHj0gSCbl9C8oQKSBPvlIqXsxqTd8S0d5//sBflzpx5Uz9I3+SPehk9wsYFRZSmmLJwnixVpkO1Q9XbZzxcl4kzKLHzvL5OAxS0herUQWhJ8JxAqQkIeUL3IK0h55V33xVFVkdcPTvPyOFjEA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: q/9cBShCsG4bNqeBAvNPw8X2dMPGwHqGgq0W3AGrXuLos6k3UlokcF8avPGk8t+Tm8V6tQcSCHSABCjk4UxuZvkMTNY6uIhZ3w5gJli47HK0d4TO4wPC3mKAxbfVCfZswCVm6iQZ3b0VDMHI3HSPR7bTZcU8EJKIIVHDZGtKXmQRoF3328h+/FgoB7AnEiJWa6zH/egtBF15rQcDwkG3IXCSH53ha9O748N6YmrJFSwbLgXWFBBPEEuHdQFTGUcn+ldLiEbDsHsQtGF17Q63hSYKXeICXQCQ5EZB5ELyK14szo0GV+vyTSQNFv25I5xO7gLJ8mSHZYa1g2LrbNwq3es6XZRPsEpWE4DoudScrcjvyLZwSY6q/WyYNkyNyx1MWQHVGSmO6GYJe2GSbuqLBIKZkJ6OHCNjti2Uqygurw0sO70k24JpDMxNOiGdzVMwaRswn6YjvLeN8vtbIrkhlmytK6N8+jxNRTDh/RQRVeyX9S8eOBE89KUz7+Mc5S51492e6R9ekCT+cYnTGhtnn9Xi29lu2+I/1L3egHsgDvf4PIZ3LTWAwBiLd9hdAsf+s9UMIq+xVzvKAIFG0/DkTBSwBor125YcaCxBB96H68Q= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed19ad93-1d38-4e99-f99d-08dc4d9a28b1 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:28.5404 (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: WV+ytPJWXbmzfjaCN1P91X/DNYXNNCMTXRVFpQmq8q2dGXuk/gqp15LazWtogYxIDuWNKc+qmT+syGFY13RqQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4749 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: WtbpovwVzsDrv32sZBONnlFbRTF0GYl5 X-Proofpoint-ORIG-GUID: WtbpovwVzsDrv32sZBONnlFbRTF0GYl5 Support atomic writes by submitting a single BIO with the REQ_ATOMIC set. It must be ensured that the atomic write adheres to its rules, like naturally aligned offset, so call blkdev_dio_invalid() -> blkdev_atomic_write_valid() [with renaming blkdev_dio_unaligned() to blkdev_dio_invalid()] for this purpose. The BIO submission path currently checks for atomic writes which are too large, so no need to check here. In blkdev_direct_IO(), if the nr_pages exceeds BIO_MAX_VECS, then we cannot produce a single BIO, so error in this case. Finally set FMODE_CAN_ATOMIC_WRITE when the bdev can support atomic writes and the associated file flag is for O_DIRECT. Signed-off-by: John Garry --- block/fops.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/block/fops.c b/block/fops.c index c091ea43bca3..34f788348352 100644 --- a/block/fops.c +++ b/block/fops.c @@ -34,9 +34,12 @@ static blk_opf_t dio_bio_write_op(struct kiocb *iocb) return opf; } -static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, - struct iov_iter *iter) +static bool blkdev_dio_invalid(struct block_device *bdev, loff_t pos, + struct iov_iter *iter, bool is_atomic) { + if (is_atomic && !generic_atomic_write_valid(pos, iter)) + return true; + return pos & (bdev_logical_block_size(bdev) - 1) || !bdev_iter_is_aligned(bdev, iter); } @@ -72,6 +75,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio.bi_write_hint = file_inode(iocb->ki_filp)->i_write_hint; bio.bi_ioprio = iocb->ki_ioprio; + if (iocb->ki_flags & IOCB_ATOMIC) + bio.bi_opf |= REQ_ATOMIC; ret = bio_iov_iter_get_pages(&bio, iter); if (unlikely(ret)) @@ -343,6 +348,9 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, task_io_account_write(bio->bi_iter.bi_size); } + if (iocb->ki_flags & IOCB_ATOMIC) + bio->bi_opf |= REQ_ATOMIC; + if (iocb->ki_flags & IOCB_NOWAIT) bio->bi_opf |= REQ_NOWAIT; @@ -359,12 +367,13 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) { struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); + bool is_atomic = iocb->ki_flags & IOCB_ATOMIC; unsigned int nr_pages; if (!iov_iter_count(iter)) return 0; - if (blkdev_dio_unaligned(bdev, iocb->ki_pos, iter)) + if (blkdev_dio_invalid(bdev, iocb->ki_pos, iter, is_atomic)) return -EINVAL; nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1); @@ -373,6 +382,8 @@ static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) return __blkdev_direct_IO_simple(iocb, iter, bdev, nr_pages); return __blkdev_direct_IO_async(iocb, iter, bdev, nr_pages); + } else if (is_atomic) { + return -EINVAL; } return __blkdev_direct_IO(iocb, iter, bdev, bio_max_segs(nr_pages)); } @@ -612,6 +623,9 @@ static int blkdev_open(struct inode *inode, struct file *filp) if (!bdev) return -ENXIO; + if (bdev_can_atomic_write(bdev) && filp->f_flags & O_DIRECT) + filp->f_mode |= FMODE_CAN_ATOMIC_WRITE; + ret = bdev_open(bdev, mode, filp->private_data, NULL, filp); if (ret) blkdev_put_no_open(bdev); From patchwork Tue Mar 26 13:38: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: 13604189 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 AF7EF128381; Tue, 26 Mar 2024 13:40:21 +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=1711460423; cv=fail; b=IM3c4CXYpzaW6vRgOWLyFXrFzE5v8W75ynXu0zPL87i+dbK4lWO0L10qKO11o6rJ2hI4Li9H7ZQ+m+SlyuujJYd7y5ljOpvkvbats1SHpr7km77swxBGMmkFsjDo+9DnKQX+pVac6XTdsi1ASivnEzlHPpQ/yPe5uqe7JOP0l9Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460423; c=relaxed/simple; bh=JXSNxK9cDtJSoN/UbWRvXS7b5x/okZx5VtGDsx4kt0U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=b4TPdIKGh6jq4w1T8yAA74Alm0823AaqMJgwbJeMihjF1nXRUuwuPMnG+KjAy1zU3ZBm2KSK5jbxPRttRHOmAOEMwOpaMdLoZdFSR1bVrAFtW838bo7pegzqCJVQZhpZ/iXt1kRRInYUEoKdQ0UIgnYz5QyBbYrfJM4xa5gwOd4= 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=BznG6CU7; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=igPSKwQs; 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="BznG6CU7"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="igPSKwQs" 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 42QBnktw012046; Tue, 26 Mar 2024 13:39:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=ufvOEddQUi4BQyDLIyJUOOMPVlMZbkOLPpmXrIN9h2o=; b=BznG6CU7cec+GVz1HQsJpylA17Mf8QGaBs9MjIkdXF4A9jndJmPFj4/gIi2gxMAeCgFm Mz71rUdakcn6D3QJvSWXxRxkohUX3PSAJt7mqZK2WZOF9tWKWXOxnbjud4a8DwJMMrkY KDwaUN7aKRKhDwmybAqf6h1Xyp2gq7PnkoMcLd9Vp80wGwWOztns1aO+INPq5pf2Q4zD Ipu8itu3KqeOyUH6JHPeCbjv/ye0H0+pooQNz2XXzK7R53Sm/Cb4HuTyVgr5RiTCOUZA W2XJjH+XFrHdGiPZMvtSdYLem3u9FuH/wFD5HI9FttSguE+aaQhJttfFtjUO6T1/w82e Pg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x1pybmxfp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:36 +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 42QCMRsG017540; Tue, 26 Mar 2024 13:39:35 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nh77x2e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KkUynzSuSiiQvYmmw1VTfREz8xZiyyN5EifVi5YCICnaYI8dmP8/86jAk7Hrqq6dHju9VWmdD/TAMR11ODuudRMPWLXoia122CT2GXAD6AK47IGtj1K/yuVOV90+cm5A34Xf02cTRk8os+4+hqhUORIrlOM7izMESXcHOROCbsmEok9dIGinB2zj0DaPlMx2tGmtGBCxw+/UXdezRUheE977Gro3HvWcsd6QLR9pAxYWmtV7BVDZwlsqgB7/jqHgED8P2r00WilW6zLOmq/Xdzec+aPX/7rjg1m//YFCYH5wkGCaCjNgoS7JJxKtxyFnwro7EJaWkiVZS20h24Gliw== 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=ufvOEddQUi4BQyDLIyJUOOMPVlMZbkOLPpmXrIN9h2o=; b=ZRJ5ad9+zPSK8KLconxdS+sIVj0e/U3eRZLAuZR+HBYXUthS71x1puldVXbo7i+nEcYHEvOvxXTt3WpFealDMBKrDkK7Bfs0+E5HBkDGs9PKa/ndXQ9oaMDgI7oNREftefyDmxdfAGuLzkJp+u0tiNSqzODyjgOjVnG3SQnXp5V52yP0XA0W0Af4ljstHYsmfpytostGOojgqrDY4u9wxXGVXgRwQ0k71AlyK4JktPyOjw9R6gKNEK24hHrSTl8cu4IdCwiiMninYFfL6C4TIZRebj2LcQLaFZC76ofxzszW6+ABnov4F95ZIOdaTJpofGrCJfvFHKTgOLg1xTgLUA== 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=ufvOEddQUi4BQyDLIyJUOOMPVlMZbkOLPpmXrIN9h2o=; b=igPSKwQs1IPSwUWxQRd7RW/G4zheOKPY16AKbYQEv/MBDqxr+2yzzZunCKE8BW8TvnZeT/vOKPezr3uuf/+OWQKXGCup17KoIB8pKIaQ0W1umQVFkkobLfCqATF0tzhfkT+1UshvbJYn+H3QZ7FhIGfFvqrs69kDWqAndzT2Pko= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB4749.namprd10.prod.outlook.com (2603:10b6:a03:2da::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Tue, 26 Mar 2024 13:39:32 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:32 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, John Garry Subject: [PATCH v6 08/10] scsi: sd: Atomic write support Date: Tue, 26 Mar 2024 13:38:11 +0000 Message-Id: <20240326133813.3224593-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO4P123CA0004.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:150::9) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB4749:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9UrGTh58tq1OzkJPqky6jgV2qvK983Ls2L4pxS3wBy4hEJQectNBmPfKV5Eh/Tsgto5D6C2zFvRNvIR4XMOnZwGOrk4LV6Rw+uSacp7n9S1CbBvsI5pBi4E1eMQJ4J2pKtRDIQVjFAV3j2rFHgN3gJQa9WxwHqnmOtM3uGoYMB8lFRZLTRTCxTyaOWW3MvlMe0YFbbKfjw50w9zpSrJ2dgUwH+IhVAmNi6seLZTArKEVCKF/qw14we9LK+afgUwwdo0ow/3x6xIh5DFY4rN7tgAr+yzvUntyqzPPBI4dUpL5j/To5DM7+/iQuRrw0lYRagrSzDKe5Dgm7K94qjvqe2QZg/jYwfzQ3BRHq3suCatXKFs/CDVNEtCIbvSgX8nCihAI6uHnERADdglbYpc5qUuZ+yqWOBlguTDSPdmO3d5pyQ9HWgukjIWyQ/SZmXh2KlC9U50jwLkBozwGlr1KyTExlw8sPqmplOh//kFC4GwIpU6stZI1MnTt1ktHMLoWfrR1bF416pWgxlCkyXExJo9GVG/jl6mNcJMXbgfmMomvctT/1L17oITczvXSd2sxG+GlkOGzsRv61IUQZWKPxV6V0FRintzDaIKWOK0+8CYkDLCBz7IteKYE/SMEE8YILfstTI3CUAMiALeohKjbLzY2w46+2RX9zEKmvAgcgJG+oD9sSIDmE+UU1rOCDAllHEFeaGqvTFDFFacXNIFkdA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(7416005)(1800799015)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K3+AseqdM/NyMLV7HkXjnJfMgiQLHFpzIwV8fJZBCrPJ7ZlTlAqO0M2uyy/2H7ileAcKeWIarWexHlwL7Tk31YIGxG6e4ngE8ZgQ8YQeYTXBNzIh7KXlwkuYp2trafAloDDkaw4z/2HnjJ2n3TTUOC+YV02PxIbV9PuQTZr3KZbYBRD4L3W+fMqeQhhIGnq18lotq7SZC9QmHI7MNny7NTVoj85IkDwxBNDEH/OnNgFhrJVIqFWb66sNTrL0phJRJFAzEVcdq8vN3Cdvs9o830YQBhIcavAX5gSFnz/giBuHz9EC+79bPpx5XTQ6qd02qxBNWA6y80xMUgXlWtmb+WIOHqmNeWu2bEu2DjEoNrrvTZiwiGtcCVm2i/aF2zNVTipw4+1Ak8xIjVFF5LgyDC4Jets5TRYdqLBzuQClM4MT3JZ5UNeNnUV1Ej7h5h1zosVbgSk+xOxC7rUEfZ210vFero/4/Q2oOzXEQLILh/QVwYWtD51TuEE2OJYNJo0wcLAVydHDsYC3LZKz5uZbAx/KabQKem4+w8ZFiUXKfHDUvE+MjYFVV26qcszZKR4c42UunuL4FkjjpF9qMUgSfqMKxVez9SvPTaZytzSOiqZLs3S4rbtDPqt8QTAja2YbAsZ0KG6jbC3nsdaQ7JxeU8AnZWCkhPJwAx0ixOIpwTlWcV32g7sP1OH+oyRPIbsBVPqClqcrpSyetku/URvXm6UChIlD4uzPviqEsT21PRkgK1M0wLcCkFkRmZeGxVmN18gkL/rzZGeVz4MmVQ4iVN/vkKQuhMdUWHxNEBAnEQni9g+pAp2yvf00ngr8Xo1fn6SeiV8sUxyUQRutw5+iN4ZUyAhA/dHnitl7TbmlAj7iEnQkIhdcY5XAkb2IOFmu2cXIo83p0p/uZnOEn+9qzmUBp/pIbDJPRf8pfJXUsrxqHQnFPdeGq/kk9as6TiE4JR+graxiNNj0f3bOQohQCtTVw6X77OMLufw9X8iSmM5Tkb4UO4W++NzyxYFywr6iB9VVRtDxs1//18lp9iaA9yQeY4wWkoP/aqkv7+jvuZvKDwgp2Apof50CyudEeZOPZE5RwFTlFuPw3VBMHZFsgBjYEpu7VdpwwH4CtY3s5rbdDxiWdNq5Dcy8xusp4Cg2J6Iod6KHPCBf4iEE/r6NSjDnbL12mrV3Z8Z4JAID9t84m+esz+Jprsvec81QHneGUKIcZOkX9Ltxc/nvPMI4t/ANmuQhoMAPxuD+KFtNokS4IB2K6TGdOrrP3PtCMjyVqsG7hoPty9n5ldMOCpEuQpkhezxbeh5s4QnOe0gOvZTlZeor7KZVTakkyEm+EMlbTC40p3S5T7mK7XKiTODspMtVmaGPjhDOGKrCNUxPGWPwUZsFN1ea59XscmNhkXcUadyL+5n3B6JENnD0kJw/dEcbYGA1UfYymrUVbesZwV0wpdJb4WMWaPxhxrB7lUOQJoEdJMltMXhTCByFlNynTmNDfw64tzYvkaQ0QgrfVTxFXCi6QWSgyn38f6Xv/zCJIwehbdlkoTNJxzAzZVFiT0zA9X+ro457gcZWmpQkgsI7ziznmPXVoixbW+lu/+lHnsMwweG5Ql1WhRXZVcOtIg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Kwt6HmdBbiAjfQ2G2v4cj6gfvMpKwHijNde01GW0ifvPRkproLgNGNm1gXFWRdxoR1Fk8WQ0GcvvBWnjeld5InZjVA1Ygg6onCjvRSUl0dLFhUnTJts7JCJMODcvCoGJdsA9J1pUQoRSS4ZEn4TGgAaUoMM9l8ljjHdPcf0G8+kZnF6XLzht1SLAOJuNeufXdFALR7Cfz/r5h11VlzetKe2OFWBVCqcIgVPoEtTSpaE4FQKdJMijmFGpq2c1LgDsLiBH1WOM3rKeFOBwizJi/66hKhHN/bsddN4vr+RYxyLDlu2ZYNpsUjUSyj3PVFmRJYK31tpzpqevTo/WZf4ohkg1V5vPZpc4WAW2Jh0R2081DKr0VOH+Ik+GCWSTE1NWKP1TEH7AqfghiFnuHSEsL++/Pt7nwlX4dw2R9gDpNL/2bdHsXwGs8Hyv/3qdDK+4tXRJanmD9o/ZNGw+KhAi9MfM0PnHvj1BFpOVzbGp1H5OoTpNrqsL0Ap8MbiykHut42MdpaCzRdH6NCcR1qTMNaD/zVvETslsCJjVvc6j8JG9MUV33UnWnLv5WF4krbUCJ8a9kg0d1vbMWHZD1GV9veues5dAuZowd0hSLbs/Xs0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 265f7778-ea66-433a-1ad2-08dc4d9a2ae2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:32.2395 (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: 9GPbfy07pXoy54EDp0lU9FTtD/dTKPF5Tywl6HhwHNxFPBwsnSx4suEzcni4tUe3w0RjWWcuZBTiKhu0Y4omdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4749 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: 9OJN8y4faa2TxX0uyeJjKBsMWn-Z4ICJ X-Proofpoint-ORIG-GUID: 9OJN8y4faa2TxX0uyeJjKBsMWn-Z4ICJ 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 ccff8f2e2e75..60046299844f 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -917,6 +917,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_bytes(q, unit_min * logical_block_size); + blk_queue_atomic_write_unit_max_bytes(q, unit_max * logical_block_size); + blk_queue_atomic_write_boundary_bytes(q, 0); +} + static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, bool unmap) { @@ -1208,6 +1267,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); @@ -1279,6 +1358,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); @@ -3220,7 +3303,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]); @@ -3251,6 +3334,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 5c4285a582b2..bc376ebb37ac 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; @@ -154,6 +161,7 @@ struct scsi_disk { unsigned security : 1; unsigned ignore_medium_access_errors : 1; unsigned rscs : 1; /* reduced stream control support */ + unsigned use_atomic_write_boundary : 1; }; #define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev) diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 843106e1109f..70e1262b2e20 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -120,6 +120,7 @@ #define WRITE_SAME_16 0x93 #define ZBC_OUT 0x94 #define ZBC_IN 0x95 +#define WRITE_ATOMIC_16 0x9c #define SERVICE_ACTION_BIDIRECTIONAL 0x9d #define SERVICE_ACTION_IN_16 0x9e #define SERVICE_ACTION_OUT_16 0x9f diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h index 8e2d9b1b0e77..05f1945ed204 100644 --- a/include/trace/events/scsi.h +++ b/include/trace/events/scsi.h @@ -102,6 +102,7 @@ scsi_opcode_name(WRITE_32), \ scsi_opcode_name(WRITE_SAME_32), \ scsi_opcode_name(ATA_16), \ + scsi_opcode_name(WRITE_ATOMIC_16), \ scsi_opcode_name(ATA_12)) #define scsi_hostbyte_name(result) { result, #result } From patchwork Tue Mar 26 13:38:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13604191 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 2EA4174E03; Tue, 26 Mar 2024 13:41: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=1711460505; cv=fail; b=qXEoxxjU10zGuZgbcd9fRLiLUO8KX+w/5jBt8Z2bZzRVz8Fm2ZZEVkzN9T2qRp45FlxP1oqJyTeg5LKgJ8lRRviLIJLviF+RRoP903Eu40o4SWi3Z9IvYKTSbeIaf5DFUTBSNCgAIesNpWH0M9DFM5/e8VUr9ay98//7Zid9C9U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460505; c=relaxed/simple; bh=R36bax9aDLUanI5xVDnThFLhPtFRZWJmr5/8ECTae8w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=aeHVtuWyuAuYxCvFLB8JEhZC1MZ1TSKo+2S6/bMsaQ4JnLCkBKXyZu7wcVy1bOnmNOrRtWIOjl2bmbF7MD58V9xwQzZL44DCztD3DZW6ydWWOpdxzDUr4DZLxzqm9FFvqIQLrAb+coHV/dImemXR7NujAK2Abs4LRIP/1+Q/mc0= 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=mdPzJJCy; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=lPLi4Wly; 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="mdPzJJCy"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="lPLi4Wly" 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 42QBnXaZ009228; Tue, 26 Mar 2024 13:39:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=p9eg8fdWXMhNGFlIiazULYvvLmp/RlUKAMPSz6Wp/aY=; b=mdPzJJCyelttEeij/GJvmqyhjyjDoaR30Vk2MqFtEby8Mf4gZ+oegOsU35HoiDDHOq2a GnOscCXEkWeLaOJzHXRicE7HV06CsfL5Rzxhv1hUlfxMb71NoUDRyJVJG9i5Se58OZcn TUMj/xijiopy7K7OqaPVku1uSL/x166ToCLly+TF83XvGhbEtgq4cTOrE268V2X2ZhQe Es2Ot5Ui76nbm/shlOG2b64X3ArPnyCp0bfJu6aqqEjeD/ZGyRd0ljvXYV3XwyVypH2X 68mXJ2eDZPIXCYLgSH/d2RHWduZa0pi12qWBTor5JKxhvC6fhFGwAcwFhx5dQpvCJBxs OQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x1pybmxg1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:40 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 42QCMTti013259; Tue, 26 Mar 2024 13:39:39 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3x1nhd8uy4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wo5xsR+qKkudGGY38mWqdbiKSHwnOVfhydBdKHCCiIhZgRMv8I19htb8crh6Wz1kU9JNZb2hMsXjzJVTKjB6f3ejE2i6y8/6vYSKJBfoyiO7dyNhZidvhRIPXVrlK6bKVbQsFIUD2DbGHQ6k+GTeg5B7rYnHahx2ekNPrMr+L9Dbyk5pjLskZySUo93dY9JLBHuW0kWg3DHlEyqVmdq+03TbA/IAzXuGglkvxwnZwSLcsufmu+d3tDmLkSmOXWFzHeYJy7TMcqVcb2vAaSFJ3jV5mgdBDgg9IE/ALkj7jJ/trfOjyxymo/OPZaCmqy56hdloZmU2k613Ubog4W3abA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=p9eg8fdWXMhNGFlIiazULYvvLmp/RlUKAMPSz6Wp/aY=; b=Ah7WPS/IefdzDzCZ1a+1nM4u5ByZq7yZ2Hyxx51RrjYjoavdiw0L2GaUzmvJc9NMdG6IjH5eTf1TIqi/0uhBZ2+OhYLCCoMG4e/g/wdYAs66B/4f7mo8nTgbivw5U+T0QdLx63d2BXRoTz2vKvAFuPD1N419Wnlv05034hoInQiszvVh/nImWjouEg4YMX2+k4zPkXHHd4eT1Z5FdC/pETIRrlMsLU26zD4H+znpsdq+QZ2M3ZHVlvtOAudKt698FkhUPvaPWq66dsP1APyHnlkLstAMgmasKgzC+iksxCCx8KO6mS78FJmTOC0J3XoBTNPogHgQ56SCx8E1g7MOKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p9eg8fdWXMhNGFlIiazULYvvLmp/RlUKAMPSz6Wp/aY=; b=lPLi4WlywRxd0+6UwJfIlad7KKkCSDwBrcvdJX6887JwTzvZtvdIdRlx6uKRoJxyPkjd67lE46iZct8BSApsWP+btrpw7BUUGMq34m/XGLqwEmTZniUVx7ylN69BinoTOY2ddc3OmXsGv7i9O9LR/x3rBWPnpf5c/+lvdEG2RwQ= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB4749.namprd10.prod.outlook.com (2603:10b6:a03:2da::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Tue, 26 Mar 2024 13:39:36 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:35 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, John Garry Subject: [PATCH v6 09/10] scsi: scsi_debug: Atomic write support Date: Tue, 26 Mar 2024 13:38:12 +0000 Message-Id: <20240326133813.3224593-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO3P265CA0020.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:387::14) To CH2PR10MB4312.namprd10.prod.outlook.com (2603:10b6:610:7b::9) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB4749:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qzjgpoxdGYYEChG3zD5taOcdDCJAfMhmkGGjr7U+/XGieU872vU/6NBlMKFbBBmUY+1bj9vRE+5UYZKZKq0L9kN9IfWJcuxL5FJDv7ixCWLwoZ5iG/98TJmiPXn2EfioFHdNWYjmGBXL80dgFnmcDxupuh1nL9WQ4UAGaV0Nihw70RzQIkd6n5037QskJj7PSlqaOkkuphzhooWQsWtA30U+xnw4MjSt8ffkpOFeGf6HtjN4S3dBCsV6E3dndiNqvcKL+xB85BblZ/Tm1gHyZmqW9+V0VGM9SMYah/28IAA6rYkO00ecox8U/9GNomxTzbfMKPaBg1L4Veg/kvpCYAvLYhLR01dGjGaOra1x9fub6Du6G6vfB9XDNoHS8HkI86DY3sD201EUzcEMfpexEeDJCSc9nPT90tuNAUh9MHuIys26zXrvncgKhIhxffyYE6r++SQojwvV9tuoeLwUAWM8p3EWIKXLsWEXuRJ+XvYpt7lX/6uf0ilaicQ41NXj3NFPGcTPtLHX0LL2W4X57A78unH43n1PLDMDv2cGAD8Un5Xm7IUiREuvvqli0Onhcn1G3FPPyg82hGHPRDm4Pej0AK1lgf+6sN58kHu69CHSeTxtKOprAIUlVggLW+Uf/lp9QLdwpYZYTx3mO98urdhmRqzW82OQvvh/7mu03xHdUxM0mfO4rgZuLpeN3RD1zbf4jc4eX4Kl7wKmfKRwOg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(7416005)(1800799015)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 08bo5KrJpakkeZrkvS5aL75leyCj8PfyR9/kt2gC3t4PkkvnVWsZ97Q5u1rKQClHy1LIdCJOvFo64nm10dXJyjUUyFmCZT4hagQdbO2dDQ7NQWwMJ6lrDtFdm29wdbpCqSNRSbOb2XIuXD7+II4VOv7IPQrlDDX1RopgLHutT8ZENSlenaE77xOR/E0l8ro/+TGcKnU858hULrp80Qnsd/GDKmLAThCvxLM0xduuc+3Un8ALyM4WiIJMLUIKIi3sASob/LEPaf3mPnyfSlt9A8TQq0Dffp3Ly+zgAKWYvAgbLRlBXJVCV/85gh9m8NaIv0JhyvNJTlk/WB/LwQvEzpvZksweod4685hJbvgsiSwuZkqXiygW6UAfB1WcrqiQbKw27MIdzZg6x8IfEDp4qM6Y0eyGP2QsnkOoFZ5ooAy0igGWrkSgwecoT9sgE7KQ3uVN9OhLHMM/KU0ziJ6v22HQh+jmuKv28+u5C+Eb/27UeQgbUATNTOlXOcPVAVs3paMAHmRFCx3iDL23OMddg3KxVV420kcp2Zkqxe7XhVamVSFwTEk9URUOl8Dw0IlItYN4t05/XXIctXDF1CGPe2h9/nY1nZyfwmmlNA7/IEZbtrrosUa3jCBgRoERDbs45tRQu16W71Jx6+Riku2UDke0w9Su44nkNBkQUFovhH20Nm8F8wykrX/YF2igeNcbJh9w3mABL8sqkblU736WjBVN6XdQcd2OyAJXxJqJxXMNSAZ+6ucTWE2i/kcDTXBEZlBoZ+PImOZQ9FSaz9L82DY+OjvLHcfO2rIMoaGErXs4qxHlsG3lnt+KCZ7BAh8J8ZUPfms4W527+LGrBcn87qp8P6R4ey23PkA3uznkZOdZ8VqaJFQc/co+bEXbq02udksApgk70zaxJxE3f2LfVJTgWI2HLMpC/12J54R1HtSw+2+HJ4MYpTQq5UG2g8Rmvju68wrHeobwiWkp2lYBSRUc5z35HRnhQ1ILspYb0/ETP61LmHu/ohV/b5tiSrpeYEExD3DoKINZsSZtDBOzViz7Ao794ojQ2PWozBasF0Bt4wIQhNKevTAKtYnopAEYh5JpkUnDjCfZ7A0z1IpJ6qeurrwoJ+w0WAk3ozh7guG78sfkW7DMoM7mcqjd4JgDsRT6OA1/ns4dwKYWsBREIVS4s9n+tke7Pp6AvGjjoaVtfoKRkTDMbQDM9PLVzgRh8Sw9yIYF27HgA4WsSN6EeNp6zlJnPHPqis1BYcpDAilMjlb3GdA5VBEwBjsDJBFxeJr0syFATjV4HriMBsz8asX+ZhJYoZFJ+fUX1U5qvPcN6PI+3WHaGQVud50uihi4iKZRTAVyGZ2rYUltSQVmJtyw1W22NBFNulYrOiy/wk7745EAzjaaAwExvtChHRqDpLCjFU/Y3Qbf2stNvNpYTJsCIRhMEtKisTeCmOkjnK+CvFS5De+4dvn9luZzkJA3eaNq27AL5W8JaHJOCL0dMWlOa+uSatrDh7ZMByFYuo3DkRxv+4xoA1WF0Wpw1HU1xtAS0uwkew/QmW8hhJx/UMUef4Qg6ELboqK9dd2kHXm0KgyfY0d9wG1P7RlVVrAmmnh3Yh9kpy42vI4u6McL6Q== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: uC1iDwk683Qwk5nEWOStpn5onHogxPOyk5dfI564xU1V7yD3jvSQXWgxI2n3OgaGWqyAAjwPV1YfZi4kh/+uq5m9dmaKIwJxOm1MzAZQeLMOIakKB0v/TxEmQ8f0QIV4+/RsYLji2wBbzwt5Yfq2owSOTBlWLV3+xGP5Q52cxJziI3rhi0egZtgWCyp6ofEFkJZpRrON1nYEKbEYQIQgtIX09QOdXv6e26I6DVDhjGEjf4v/lN+Gjg7tTEhqaFXeCXqzO/jjm3PWVMxEdCbvBVAx5CSqBLudy3O87iUGVNEq2A4c86Usw50wHvZVnf7LtVK4t4jhCw1fAKzcn5GXiJUkQOIhz/6xfNM9L5MC7IKUc2d1hdhnipFGJj1bXpbipKti2cjYkjCO44cYBCxBqritt1+VkpO05WqhW2br6WAalJeO0jg6Ie9LlSRjHlntraxX/am0rgay4bcYpSaxhgl2S0IcKAIn9IUSE41gQNtZIbAsskStHMXnrZNMM8wyEBum8SYC7UuoYKCSg+rv+WaGd3aXemj00UYvYa+kSMBpXJjRVsMt5od25oz8HIRh/3E/j3oRQ65RFDUlXIyxdfu+jMxeZiNaiFQwzdHOr4I= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63b9afbc-fdc1-4bb0-8800-08dc4d9a2cd8 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4312.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:35.8882 (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: ngsP43k3xEEoItxC1CW4usm/c+z+crRltvYlfzhW+JrNk0Kos8o4IqP0MbP6GpwVB64tpsvXG2kTH1bG3Bq9YQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4749 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: IK3VTLR6kpKY1iBmE1BN3Y0NehgveLmm X-Proofpoint-ORIG-GUID: IK3VTLR6kpKY1iBmE1BN3Y0NehgveLmm Add initial support for atomic writes. As is standard method, feed device properties via modules param, those being: - atomic_max_size_blks - atomic_alignment_blks - atomic_granularity_blks - atomic_max_size_with_boundary_blks - atomic_max_boundary_blks These just match sbc4r22 section 6.6.4 - Block limits VPD page. We just support ATOMIC WRITE (16). The major change in the driver is how we lock the device for RW accesses. Currently the driver uses a per-device lock for accessing device metadata and "media" data (calls to do_device_access()) atomically for the duration of the whole read/write command. This should not suit verifying atomic writes. Reason being that currently all reads/writes are atomic, so using atomic writes does not prove anything. Change device access model to basis that regular writes only atomic on a per-sector basis, while reads and atomic writes are fully atomic. As mentioned, since accessing metadata and device media is atomic, continue to have regular writes involving metadata - like discard or PI - as atomic. We can improve this later. Currently we only support model where overlapping going reads or writes wait for current access to complete before commencing an atomic write. This is described in 4.29.3.2 section of the SBC. However, we simplify, things and wait for all accesses to complete (when issuing an atomic write). Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 588 +++++++++++++++++++++++++++++--------- 1 file changed, 454 insertions(+), 134 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 7f340a59fdc5..fcc9640fa18a 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -69,6 +69,8 @@ static const char *sdebug_version_date = "20210520"; /* Additional Sense Code (ASC) */ #define NO_ADDITIONAL_SENSE 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASC 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASCQ 0x23 #define LOGICAL_UNIT_NOT_READY 0x4 #define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8 #define UNRECOVERED_READ_ERR 0x11 @@ -103,6 +105,7 @@ static const char *sdebug_version_date = "20210520"; #define READ_BOUNDARY_ASCQ 0x7 #define ATTEMPT_ACCESS_GAP 0x9 #define INSUFF_ZONE_ASCQ 0xe +/* see drivers/scsi/sense_codes.h */ /* Additional Sense Code Qualifier (ASCQ) */ #define ACK_NAK_TO 0x3 @@ -152,6 +155,12 @@ static const char *sdebug_version_date = "20210520"; #define DEF_VIRTUAL_GB 0 #define DEF_VPD_USE_HOSTNO 1 #define DEF_WRITESAME_LENGTH 0xFFFF +#define DEF_ATOMIC_WR 0 +#define DEF_ATOMIC_WR_MAX_LENGTH 8192 +#define DEF_ATOMIC_WR_ALIGN 2 +#define DEF_ATOMIC_WR_GRAN 2 +#define DEF_ATOMIC_WR_MAX_LENGTH_BNDRY (DEF_ATOMIC_WR_MAX_LENGTH) +#define DEF_ATOMIC_WR_MAX_BNDRY 128 #define DEF_STRICT 0 #define DEF_STATISTICS false #define DEF_SUBMIT_QUEUES 1 @@ -374,7 +383,9 @@ struct sdebug_host_info { /* There is an xarray of pointers to this struct's objects, one per host */ struct sdeb_store_info { - rwlock_t macc_lck; /* for atomic media access on this store */ + rwlock_t macc_data_lck; /* for media data access on this store */ + rwlock_t macc_meta_lck; /* for atomic media meta access on this store */ + rwlock_t macc_sector_lck; /* per-sector media data access on this store */ u8 *storep; /* user data storage (ram) */ struct t10_pi_tuple *dif_storep; /* protection info */ void *map_storep; /* provisioning map */ @@ -398,12 +409,20 @@ struct sdebug_defer { enum sdeb_defer_type defer_t; }; +struct sdebug_device_access_info { + bool atomic_write; + u64 lba; + u32 num; + struct scsi_cmnd *self; +}; + struct sdebug_queued_cmd { /* corresponding bit set in in_use_bm[] in owning struct sdebug_queue * instance indicates this slot is in use. */ struct sdebug_defer sd_dp; struct scsi_cmnd *scmd; + struct sdebug_device_access_info *i; }; struct sdebug_scsi_cmd { @@ -463,7 +482,8 @@ enum sdeb_opcode_index { SDEB_I_PRE_FETCH = 29, /* 10, 16 */ SDEB_I_ZONE_OUT = 30, /* 0x94+SA; includes no data xfer */ SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */ - SDEB_I_LAST_ELEM_P1 = 32, /* keep this last (previous + 1) */ + SDEB_I_ATOMIC_WRITE_16 = 32, + SDEB_I_LAST_ELEM_P1 = 33, /* keep this last (previous + 1) */ }; @@ -497,7 +517,8 @@ static const unsigned char opcode_ind_arr[256] = { 0, 0, 0, SDEB_I_VERIFY, SDEB_I_PRE_FETCH, SDEB_I_SYNC_CACHE, 0, SDEB_I_WRITE_SAME, SDEB_I_ZONE_OUT, SDEB_I_ZONE_IN, 0, 0, - 0, 0, 0, 0, 0, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, + 0, 0, 0, 0, + SDEB_I_ATOMIC_WRITE_16, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, /* 0xa0; 0xa0->0xbf: 12 byte cdbs */ SDEB_I_REPORT_LUNS, SDEB_I_ATA_PT, 0, SDEB_I_MAINT_IN, SDEB_I_MAINT_OUT, 0, 0, 0, @@ -547,6 +568,7 @@ static int resp_write_buffer(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_sync_cache(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_pre_fetch(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_report_zones(struct scsi_cmnd *, struct sdebug_dev_info *); +static int resp_atomic_write(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_open_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_close_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_finish_zone(struct scsi_cmnd *, struct sdebug_dev_info *); @@ -788,6 +810,11 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEM_P1 + 1] = { resp_report_zones, zone_in_iarr, /* ZONE_IN(16), REPORT ZONES) */ {16, 0x0 /* SA */, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xc7} }, +/* 31 */ + {0, 0x0, 0x0, F_D_OUT | FF_MEDIA_IO, + resp_atomic_write, NULL, /* ATOMIC WRITE 16 */ + {16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} }, /* sentinel */ {0xff, 0, 0, 0, NULL, NULL, /* terminating element */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, @@ -835,6 +862,13 @@ static unsigned int sdebug_unmap_granularity = DEF_UNMAP_GRANULARITY; static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC; static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH; +static unsigned int sdebug_atomic_wr = DEF_ATOMIC_WR; +static unsigned int sdebug_atomic_wr_max_length = DEF_ATOMIC_WR_MAX_LENGTH; +static unsigned int sdebug_atomic_wr_align = DEF_ATOMIC_WR_ALIGN; +static unsigned int sdebug_atomic_wr_gran = DEF_ATOMIC_WR_GRAN; +static unsigned int sdebug_atomic_wr_max_length_bndry = + DEF_ATOMIC_WR_MAX_LENGTH_BNDRY; +static unsigned int sdebug_atomic_wr_max_bndry = DEF_ATOMIC_WR_MAX_BNDRY; static int sdebug_uuid_ctl = DEF_UUID_CTL; static bool sdebug_random = DEF_RANDOM; static bool sdebug_per_host_store = DEF_PER_HOST_STORE; @@ -1188,6 +1222,11 @@ static inline bool scsi_debug_lbp(void) (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10); } +static inline bool scsi_debug_atomic_write(void) +{ + return sdebug_fake_rw == 0 && sdebug_atomic_wr; +} + static void *lba2fake_store(struct sdeb_store_info *sip, unsigned long long lba) { @@ -1815,6 +1854,14 @@ static int inquiry_vpd_b0(unsigned char *arr) /* Maximum WRITE SAME Length */ put_unaligned_be64(sdebug_write_same_length, &arr[32]); + if (sdebug_atomic_wr) { + put_unaligned_be32(sdebug_atomic_wr_max_length, &arr[40]); + put_unaligned_be32(sdebug_atomic_wr_align, &arr[44]); + put_unaligned_be32(sdebug_atomic_wr_gran, &arr[48]); + put_unaligned_be32(sdebug_atomic_wr_max_length_bndry, &arr[52]); + put_unaligned_be32(sdebug_atomic_wr_max_bndry, &arr[56]); + } + return 0x3c; /* Mandatory page length for Logical Block Provisioning */ } @@ -3377,16 +3424,238 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip, return xa_load(per_store_ap, devip->sdbg_host->si_idx); } +static inline void +sdeb_read_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + read_lock(lock); +} + +static inline void +sdeb_read_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + read_unlock(lock); +} + +static inline void +sdeb_write_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + write_lock(lock); +} + +static inline void +sdeb_write_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + write_unlock(lock); +} + +static inline void +sdeb_data_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_sector_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_sector_lck); +} + +/* + * Atomic locking: + * We simplify the atomic model to allow only 1x atomic write and many non- + * atomic reads or writes for all LBAs. + + * A RW lock has a similar bahaviour: + * Only 1x writer and many readers. + + * So use a RW lock for per-device read and write locking: + * An atomic access grabs the lock as a writer and non-atomic grabs the lock + * as a reader. + */ + +static inline void +sdeb_data_lock(struct sdeb_store_info *sip, bool atomic) +{ + if (atomic) + sdeb_data_write_lock(sip); + else + sdeb_data_read_lock(sip); +} + +static inline void +sdeb_data_unlock(struct sdeb_store_info *sip, bool atomic) +{ + if (atomic) + sdeb_data_write_unlock(sip); + else + sdeb_data_read_unlock(sip); +} + +/* Allow many reads but only 1x write per sector */ +static inline void +sdeb_data_sector_lock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_lock(sip); + else + sdeb_data_sector_read_lock(sip); +} + +static inline void +sdeb_data_sector_unlock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_unlock(sip); + else + sdeb_data_sector_read_unlock(sip); +} + +static inline void +sdeb_meta_read_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + read_lock(&sip->macc_meta_lck); + else + read_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_read_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + read_unlock(&sip->macc_meta_lck); + else + read_unlock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + write_lock(&sip->macc_meta_lck); + else + write_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + write_unlock(&sip->macc_meta_lck); + else + write_unlock(&sdeb_fake_rw_lck); + } +} + /* Returns number of bytes copied or -1 if error. */ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, - u32 sg_skip, u64 lba, u32 num, bool do_write, - u8 group_number) + u32 sg_skip, u64 lba, u32 num, u8 group_number, + bool do_write, bool atomic) { int ret; - u64 block, rest = 0; + u64 block; enum dma_data_direction dir; struct scsi_data_buffer *sdb = &scp->sdb; u8 *fsp; + int i; + + /* + * Even though reads are inherently atomic (in this driver), we expect + * the atomic flag only for writes. + */ + if (!do_write && atomic) + return -1; if (do_write) { dir = DMA_TO_DEVICE; @@ -3406,21 +3675,26 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, fsp = sip->storep; block = do_div(lba, sdebug_store_sectors); - if (block + num > sdebug_store_sectors) - rest = block + num - sdebug_store_sectors; - ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, + /* Only allow 1x atomic write or multiple non-atomic writes at any given time */ + sdeb_data_lock(sip, atomic); + for (i = 0; i < num; i++) { + /* We shouldn't need to lock for atomic writes, but do it anyway */ + sdeb_data_sector_lock(sip, do_write); + ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, fsp + (block * sdebug_sector_size), - (num - rest) * sdebug_sector_size, sg_skip, do_write); - if (ret != (num - rest) * sdebug_sector_size) - return ret; - - if (rest) { - ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, - fsp, rest * sdebug_sector_size, - sg_skip + ((num - rest) * sdebug_sector_size), - do_write); + sdebug_sector_size, sg_skip, do_write); + sdeb_data_sector_unlock(sip, do_write); + if (ret != sdebug_sector_size) { + ret += (i * sdebug_sector_size); + break; + } + sg_skip += sdebug_sector_size; + if (++block >= sdebug_store_sectors) + block = 0; } + ret = num * sdebug_sector_size; + sdeb_data_unlock(sip, atomic); return ret; } @@ -3596,70 +3870,6 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec, return ret; } -static inline void -sdeb_read_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - read_lock(&sip->macc_lck); - else - read_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_read_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - read_unlock(&sip->macc_lck); - else - read_unlock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - write_lock(&sip->macc_lck); - else - write_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - write_unlock(&sip->macc_lck); - else - write_unlock(&sdeb_fake_rw_lck); - } -} - static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) { bool check_prot; @@ -3669,6 +3879,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case READ_16: @@ -3727,6 +3938,10 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) atomic_set(&sdeb_inject_pending, 0); } + /* + * When checking device access params, for reads we only check data + * versus what is set at init time, so no need to lock. + */ ret = check_device_access_params(scp, lba, num, false); if (ret) return ret; @@ -3746,29 +3961,33 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_read_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp))) { + sdeb_meta_read_lock(sip); + meta_data_locked = true; + } /* DIX + T10 DIF */ if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) { switch (prot_verify_read(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } break; case 3: /* Reference tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } @@ -3776,8 +3995,9 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, false, 0); - sdeb_read_unlock(sip); + ret = do_device_access(sip, scp, 0, lba, num, 0, false, false); + if (meta_data_locked) + sdeb_meta_read_unlock(sip); if (unlikely(ret == -1)) return DID_ERROR << 16; @@ -3967,6 +4187,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case WRITE_16: @@ -4025,10 +4246,17 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) "to DIF device\n"); } - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp)) || + scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } + ret = check_device_access_params(scp, lba, num, true); if (ret) { - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); return ret; } @@ -4037,22 +4265,22 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) switch (prot_verify_write(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } break; case 3: /* Reference tag error */ if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } @@ -4060,13 +4288,16 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, true, group); + ret = do_device_access(sip, scp, 0, lba, num, group, true, false); if (unlikely(scsi_debug_lbp())) map_region(sip, lba, num); + /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + if (unlikely(-1 == ret)) return DID_ERROR << 16; else if (unlikely(sdebug_verbose && @@ -4176,7 +4407,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, goto err_out; } - sdeb_write_lock(sip); + /* Just keep it simple and always lock for now */ + sdeb_meta_write_lock(sip); sg_off = lbdof_blen; /* Spec says Buffer xfer Length field in number of LBs in dout */ cum_lb = 0; @@ -4219,7 +4451,11 @@ static int resp_write_scat(struct scsi_cmnd *scp, } } - ret = do_device_access(sip, scp, sg_off, lba, num, true, group); + /* + * Write ranges atomically to keep as close to pre-atomic + * writes behaviour as possible. + */ + ret = do_device_access(sip, scp, sg_off, lba, num, group, true, true); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); @@ -4258,7 +4494,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, } ret = 0; err_out_unlock: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); err_out: kfree(lrdp); return ret; @@ -4277,14 +4513,16 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, scp->device->hostdata, true); u8 *fs1p; u8 *fsp; + bool meta_data_locked = false; - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } ret = check_device_access_params(scp, lba, num, true); - if (ret) { - sdeb_write_unlock(sip); - return ret; - } + if (ret) + goto out; if (unmap && scsi_debug_lbp()) { unmap_region(sip, lba, num); @@ -4295,6 +4533,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* if ndob then zero 1 logical block, else fetch 1 logical block */ fsp = sip->storep; fs1p = fsp + (block * lb_size); + sdeb_data_write_lock(sip); if (ndob) { memset(fs1p, 0, lb_size); ret = 0; @@ -4302,8 +4541,8 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ret = fetch_to_dev_buffer(scp, fs1p, lb_size); if (-1 == ret) { - sdeb_write_unlock(sip); - return DID_ERROR << 16; + ret = DID_ERROR << 16; + goto out; } else if (sdebug_verbose && !ndob && (ret < lb_size)) sdev_printk(KERN_INFO, scp->device, "%s: %s: lb size=%u, IO sent=%d bytes\n", @@ -4320,10 +4559,12 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); + sdeb_data_write_unlock(sip); + ret = 0; out: - sdeb_write_unlock(sip); - - return 0; + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + return ret; } static int resp_write_same_10(struct scsi_cmnd *scp, @@ -4466,25 +4707,30 @@ static int resp_comp_write(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); - ret = do_dout_fetch(scp, dnum, arr); if (ret == -1) { retval = DID_ERROR << 16; - goto cleanup; + goto cleanup_free; } else if (sdebug_verbose && (ret < (dnum * lb_size))) sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " "indicated=%u, IO sent=%d bytes\n", my_name, dnum * lb_size, ret); + + sdeb_data_write_lock(sip); + sdeb_meta_write_lock(sip); if (!comp_write_worker(sip, lba, num, arr, false)) { mk_sense_buffer(scp, MISCOMPARE, MISCOMPARE_VERIFY_ASC, 0); retval = check_condition_result; - goto cleanup; + goto cleanup_unlock; } + + /* Cover sip->map_storep (which map_region()) sets with data lock */ if (scsi_debug_lbp()) map_region(sip, lba, num); -cleanup: - sdeb_write_unlock(sip); +cleanup_unlock: + sdeb_meta_write_unlock(sip); + sdeb_data_write_unlock(sip); +cleanup_free: kfree(arr); return retval; } @@ -4528,7 +4774,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) desc = (void *)&buf[8]; - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); for (i = 0 ; i < descriptors ; i++) { unsigned long long lba = get_unaligned_be64(&desc[i].lba); @@ -4544,7 +4790,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ret = 0; out: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); kfree(buf); return ret; @@ -4702,12 +4948,13 @@ static int resp_pre_fetch(struct scsi_cmnd *scp, rest = block + nblks - sdebug_store_sectors; /* Try to bring the PRE-FETCH range into CPU's cache */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); prefetch_range(fsp + (sdebug_sector_size * block), (nblks - rest) * sdebug_sector_size); if (rest) prefetch_range(fsp, rest * sdebug_sector_size); - sdeb_read_unlock(sip); + + sdeb_data_read_unlock(sip); fini: if (cmd[1] & 0x2) res = SDEG_RES_IMMED_MASK; @@ -4866,7 +5113,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } /* Not changing store, so only need read access */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); ret = do_dout_fetch(scp, a_num, arr); if (ret == -1) { @@ -4888,7 +5135,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) goto cleanup; } cleanup: - sdeb_read_unlock(sip); + sdeb_data_read_unlock(sip); kfree(arr); return ret; } @@ -4934,7 +5181,7 @@ static int resp_report_zones(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_read_lock(sip); + sdeb_meta_read_lock(sip); desc = arr + 64; for (lba = zs_lba; lba < sdebug_capacity; @@ -5032,11 +5279,70 @@ static int resp_report_zones(struct scsi_cmnd *scp, ret = fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, rep_len)); fini: - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); kfree(arr); return ret; } +static int resp_atomic_write(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip) +{ + struct sdeb_store_info *sip; + u8 *cmd = scp->cmnd; + u16 boundary, len; + u64 lba, lba_tmp; + int ret; + + if (!scsi_debug_atomic_write()) { + mk_sense_invalid_opcode(scp); + return check_condition_result; + } + + sip = devip2sip(devip, true); + + lba = get_unaligned_be64(cmd + 2); + boundary = get_unaligned_be16(cmd + 10); + len = get_unaligned_be16(cmd + 12); + + lba_tmp = lba; + if (sdebug_atomic_wr_align && + do_div(lba_tmp, sdebug_atomic_wr_align)) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (sdebug_atomic_wr_gran && len % sdebug_atomic_wr_gran) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (boundary > 0) { + if (boundary > sdebug_atomic_wr_max_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + + if (len > sdebug_atomic_wr_max_length_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } else { + if (len > sdebug_atomic_wr_max_length) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } + + ret = do_device_access(sip, scp, 0, lba, len, 0, true, true); + if (unlikely(ret == -1)) + return DID_ERROR << 16; + if (unlikely(ret != len * sdebug_sector_size)) + return DID_ERROR << 16; + return 0; +} + /* Logic transplanted from tcmu-runner, file_zbc.c */ static void zbc_open_all(struct sdebug_dev_info *devip) { @@ -5063,8 +5369,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) mk_sense_invalid_opcode(scp); return check_condition_result; } - - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { /* Check if all closed zones can be open */ @@ -5113,7 +5418,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_open_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5140,7 +5445,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_close_all(devip); @@ -5169,7 +5474,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, zbc_close_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5212,7 +5517,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_finish_all(devip); @@ -5241,7 +5546,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, zbc_finish_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5292,7 +5597,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_rwp_all(devip); @@ -5320,7 +5625,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_rwp_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -6284,6 +6589,7 @@ module_param_named(lbprz, sdebug_lbprz, int, S_IRUGO); module_param_named(lbpu, sdebug_lbpu, int, S_IRUGO); module_param_named(lbpws, sdebug_lbpws, int, S_IRUGO); module_param_named(lbpws10, sdebug_lbpws10, int, S_IRUGO); +module_param_named(atomic_wr, sdebug_atomic_wr, int, S_IRUGO); module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO); module_param_named(lun_format, sdebug_lun_am_i, int, S_IRUGO | S_IWUSR); module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR); @@ -6318,6 +6624,11 @@ module_param_named(unmap_alignment, sdebug_unmap_alignment, int, S_IRUGO); module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO); module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO); module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO); +module_param_named(atomic_wr_max_length, sdebug_atomic_wr_max_length, int, S_IRUGO); +module_param_named(atomic_wr_align, sdebug_atomic_wr_align, int, S_IRUGO); +module_param_named(atomic_wr_gran, sdebug_atomic_wr_gran, int, S_IRUGO); +module_param_named(atomic_wr_max_length_bndry, sdebug_atomic_wr_max_length_bndry, int, S_IRUGO); +module_param_named(atomic_wr_max_bndry, sdebug_atomic_wr_max_bndry, int, S_IRUGO); module_param_named(uuid_ctl, sdebug_uuid_ctl, int, S_IRUGO); module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR); module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int, @@ -6361,6 +6672,7 @@ MODULE_PARM_DESC(lbprz, MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)"); MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)"); MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)"); +MODULE_PARM_DESC(atomic_write, "enable ATOMIC WRITE support, support WRITE ATOMIC(16) (def=0)"); MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)"); MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method"); MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); @@ -6392,6 +6704,11 @@ MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)" MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)"); MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)"); MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)"); +MODULE_PARM_DESC(atomic_wr_max_length, "max # of blocks can be atomically written in one cmd (def=8192)"); +MODULE_PARM_DESC(atomic_wr_align, "minimum alignment of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_gran, "minimum granularity of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_max_length_bndry, "max # of blocks can be atomically written in one cmd with boundary set (def=8192)"); +MODULE_PARM_DESC(atomic_wr_max_bndry, "max # boundaries per atomic write (def=128)"); MODULE_PARM_DESC(uuid_ctl, "1->use uuid for lu name, 0->don't, 2->all use same (def=0)"); MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)"); @@ -7563,6 +7880,7 @@ static int __init scsi_debug_init(void) return -EINVAL; } } + xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); if (want_store) { idx = sdebug_add_store(); @@ -7770,7 +8088,9 @@ static int sdebug_add_store(void) map_region(sip, 0, 2); } - rwlock_init(&sip->macc_lck); + rwlock_init(&sip->macc_data_lck); + rwlock_init(&sip->macc_meta_lck); + rwlock_init(&sip->macc_sector_lck); return (int)n_idx; err: sdebug_erase_store((int)n_idx, sip); From patchwork Tue Mar 26 13:38:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13604188 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 2E6E712837D; Tue, 26 Mar 2024 13:40:20 +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=1711460421; cv=fail; b=oM9UJa/BmJTMfcw07hKfBFA2lixUuHcKHSmRo0Rd8eScBhSAl5kgXnSNzJj7JnfP4gEQyjEQdO6TNmfIDcNl9MICHtX4Ff88Px4jzAZnh7dkIaYHpjvWgegXw4MST9s5tDTvmVp2ZxponPCDE7VAe90uoAynil4wQGiw+y9uXOU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711460421; c=relaxed/simple; bh=8ZgCq7OWNblIWSnn7+qFs10Ve/X0QIaRdJdlbbM3VZs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ZKHhFY5K58YkJc9uaA+W8aNiu4FpkzX5Ji8X+5WPjQYcPHffw1PBuW2a2vebjlYC8j+c4byQq9Upf03XVgOf7E5s0SP7u0hgCtvH5aDyqmsxYt75SonO9c5tCCHGLoYrFO0Vu+lNyHU0TZc1NbfUvRAxns4ff9887sejPqAC2a8= 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=cCsvJ/ZI; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=MhcfYEhz; 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="cCsvJ/ZI"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="MhcfYEhz" 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 42QBnaq4028623; Tue, 26 Mar 2024 13:39:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2023-11-20; bh=cYoqx1lscjP84Oi7ok7COOGxxZzLn2MAabwh00gLa9A=; b=cCsvJ/ZI5PzvzXrjXYIatTPI+bRKLjoGdZL+7wW4jINgc48SB9X8sWHltpR8yT/HNRCE a66tMENXmBIhLDi1YQOQOjC5kHKhiAiRNTWUCM5mGZwkOyzmT1lwV1qBhfSpSLkPPVz9 Vn63cyuuliazeNWjd04jWflLHskKHSCHyzuUYj8aav4rkPVkOHfibaibHPDn15Ix8fwP pFZWwMR99/vWooHe8lP4OKK8pXEo8v4SVrjtQdxaMTFor3yMSWnJgLkVWN8j13zouyQY zKlRJzFD6QO9YfYhm/2PXsNDIivEoGc2bbTsuLnyNz6QGFjn6xompk2WarFYN+qYu4hs EA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3x28ct4as7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:42 +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 42QCMSQ2017583; Tue, 26 Mar 2024 13:39:42 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 3x1nh77x7e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Mar 2024 13:39:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GRkMLJuPp76v81o0dwke3wS/BTrsui8p1BN1sFTPuQ+w7Z3dsD5QqlheSlf+kXLXVItjYJXWCaws34RYXSekNRy2o5UqMixh5Imveth71unOuUXncAlbHxUC1nBdCyof4PoLKgqr6BSJ4+VGKQOczsl7BLE33LFnh289An/LaYdkNfXNIbRKs0EZ3HbChaooh+bYNUY1LPTMBxLsKVmy20GQgkZ6nN4hEbXg22+g6g20/p9yIg8Zt+ksACFMSPmgJAOlUIMbrYft7AExb8c3UcfeWHsi+0+Z08Kf/QZqaD5t7BuEg3mwDNF8prSIUSp+pR1AapCDwv0vkVLeuSbl3w== 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=cYoqx1lscjP84Oi7ok7COOGxxZzLn2MAabwh00gLa9A=; b=RQS6G6JLXLoi+nHsq6whwXQhLySvvFXEsvpSdyUJiUco6iWp+r8eH2z3zXBsQXo1Lk6rhUYhNDJR2plqDanWu7JBRDYTChUtPZ/brbEML3nf6l8qfxgVtHizMMiEMu1Lynf7MvB9t/MP6qw19GgR4jY12Hl/eZLQrOLcx7xylwCrqoD2zv5yGGa5Cp8e7ZfuNutOBRN+rkggtmHWlp9+naB1ndNIpQuRkaHCHAkUpTngqxQSlS1E75fiopcuWAr2Vsg/OcpMVFzZIhK76r5nWUPNUdFT7QDJpI0NGVo1zdSecvmYj6Pv+XvLF8PEppG0npm7YCGduhg12BF++qpepg== 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=cYoqx1lscjP84Oi7ok7COOGxxZzLn2MAabwh00gLa9A=; b=MhcfYEhzCyaZRdkrZy4gZHA+iv4ivHVHxTqcpGpfihpFZDRJ85hF4sDP+/6SUNTFCTBLUC3fWesvGKdBN8k0euPl6oFBpmVn1dELq7ojSpdFNLxBQH0cuGZtFZ1donPcE1tihiUFiIf32EeHEiwnJ8WJ8/H+9qm4GMND1xIqnDY= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SJ0PR10MB4749.namprd10.prod.outlook.com (2603:10b6:a03:2da::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Tue, 26 Mar 2024 13:39:39 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::ae68:7d51:133f:324%4]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 13:39:39 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, djwong@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, dchinner@redhat.com, jack@suse.cz Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ojaswin@linux.ibm.com, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, io-uring@vger.kernel.org, nilay@linux.ibm.com, ritesh.list@gmail.com, willy@infradead.org, Alan Adamson , John Garry Subject: [PATCH v6 10/10] nvme: Atomic write support Date: Tue, 26 Mar 2024 13:38:13 +0000 Message-Id: <20240326133813.3224593-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240326133813.3224593-1-john.g.garry@oracle.com> References: <20240326133813.3224593-1-john.g.garry@oracle.com> X-ClientProxiedBy: LO2P265CA0127.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::19) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|SJ0PR10MB4749:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 18QHh9FxFLWWetY2LN47rI15nhYanVXbdHU2h8byXBo9SAJUxPLhLftvMklD/j61B5ah4plWpoIbHqMoHJE+ocVTUo9I5pUhMmhnNmeO32TqySdp/Eo6NxyeN6QGzExklCh43jnt+jqIEaMKxO0BKPXxwze7+/7lJV5ZPyLWjqMdJ0uQnlLqo/oWyYjw7ZEM3a+OspgLzu4Lvaw5DCvuHHdkcQ4UD40A7R4qjR7AeeywCYjFIgxtVpJoiU40oq6i+8xp3B33PD7CrWSYJRRfl7S9yIHhgZ4B1J3YfDSM46buRiTbhTTEBqODClnYtja6HeneHrHsQvz2OJPC20K1clRVb/TH6l8RrcEptXfmIB0LAcFkh+n1hU23hR5pTjpR3oqIq2Zlwvqn8PCbhJil8l+2e+/I9LWJ7bEdrRV1bCD4H57zwv+aR73TV+Sz4QtnBcPmfh/ZtXN8SSssePQqoSGGILrV5bPZvi9y6ixi51MXuXAB+kTzp91yHebaCmjJxXzsxirH1CPMm1I1W2gEKDfdwtAdrQWN0N10EcLOW9upZHxRE+ZvGMw0xYGQaweYxfcQUXD4gztImaJZG9uf2pKerfWN0FKGM2KxOcZMI49BSPmmoZCMUvR1s4xbfMndyZ0XAkc0cXtqqiiz2aEUp/6aRGYEguBayCgIWX/wg0Z8sDqWDni87OvGS4WIoREg5HXBi3Lh9XHg5xqQkCSeGw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(7416005)(1800799015)(921011);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?HwtZoatIrhWGBrEhes7jJY+QMNg+?= =?utf-8?q?cpE13rTgnVnU+XuLD2Kp1df2z9p3ikKVdLrDuC93Ky2voEQ1oOw8oSw+UWESI/WBK?= =?utf-8?q?teNFuHqWkBiVD6SHHuxKCO0fxOMCCNpBbo9oaFsASwCC8XqJC+LPTMtOABh8vUI6G?= =?utf-8?q?TB+XrakzR7pY2Tp0ZOSPC/y5q4uaivjf/pVeXEbiko893VARGbaPLQDTFQAIIC0fS?= =?utf-8?q?m1JUQDIaHwEVfx/FC2XAs8BhOLVAylkIDNSDlnWm8fMtNu5rfAiPp6goy5mcylGFC?= =?utf-8?q?A2ekBWkjxmWIHKWDF3GqB1EjuOOx6BE8fj6JQ423Av5i0GxL9y0N9B4m1O6WRhqiT?= =?utf-8?q?1MIPW59UU1M8zEBWYHA4tjwwXz97oM/79amzwQbahl1JmUmBIsLn6cagZo6nj2Q8h?= =?utf-8?q?xYi9tpN09gejtMe2cg7E1LOU2z1amYRShvOlpWZELIFu0Y22k8cGQndM1dkNLhyUF?= =?utf-8?q?gi8b/n5UuA/PQoDqRuF+gFEmFTZoEMLmKEkP18n5o7yNViopbUkXoEbb8sYIr/ijD?= =?utf-8?q?HcDPR/mDTZFyfMTRuZyKcyFUrmlZlGGVlfFeO0F5SOfaWQXxbVOcmrVnIBZnJvW+h?= =?utf-8?q?s3JMZ4fgbFI5IQs9lTz/wygVyLsmN8NLdVcNpL+Jsh/aW4QFqMU25FKgV07F4sEc8?= =?utf-8?q?6jAkO0bDhoP1HCsiL4+3foIeu/67aWYOv0sf/bAFtXHwxaP3hjJOfEo8nIwXQo+kb?= =?utf-8?q?4Jr5I4ganu8VQSlco50tdbHzeveHx+v/tEkq93KEvAQQp2eOp6bxf/i8saPXHAEEe?= =?utf-8?q?14DMHomCbF7vmSQ56Q/VE+CiNk8CcuT3bZcsmRs1k0p1vfbkOpUi23KB3SmdoE+Sl?= =?utf-8?q?X01y63NUTPQgmf2fHjbtKW4G1GJ2CkKNECHxrzvecIaYk1Lz5q4moD+jb8nOYHjPm?= =?utf-8?q?zWQkCKNkMJbf2/cHR96ZkPgydXtbKkyzg8ox+GVz91CJC/NC7LMa6gi4oqd/nB8Mb?= =?utf-8?q?uFdWMKYV787WpdZcOHntLHIgFq8H2WKASyl+6kJ+6+71ncXIp3mGs9WdbRShiSvxM?= =?utf-8?q?CteIdGQTP1Tj41ajtheizuGbgFdnDoNa5VEPojCMghu7yQF6O5mI7m+yhLegfW2Px?= =?utf-8?q?id4x9TEE0evIGYCXoeFoaKOudNyWtP+wvgyNX8MOKz5j3p/KzCPx7AdGOAhlaIOkZ?= =?utf-8?q?SSpzAfrSPoOrmiL14nxeCixM+WHllwx/nfoR/czXOweV5Q+IVBzdRa7xAumyyxkR2?= =?utf-8?q?RFwHIMZQVwM7BKOXFMkOdF8a1g/C9cdlPTEDJFtmgjjUHWHd6UUCEX2V7ThvsBpJK?= =?utf-8?q?D5wQWaO47cFwAuZroEzxwYKPRNtlP0HFMP/Mp7bNal+y1aO/unKueDUafZw7k0dH4?= =?utf-8?q?nTwSdi7sFZRnq6I0GJWxUwLSa9JN1CmD8LdVJUTqlaimJ84NfVrMBkNtiRX6/qMiG?= =?utf-8?q?HQvsoR/8nH6rDr6feZWmeupfYuXaDylt5Q5DZvpQzuDrzOMy+fBgLbCrCA3zLgVp4?= =?utf-8?q?1CcUJzZuJFYlDd8yvtOh7u2T4njOYk3Un6XeIn/7cmXbj3Rmx1NqZE1o2sWxSejY9?= =?utf-8?q?eOLr5cUiQx/3zerxQAquAa3eSlWmW/lzSw=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 9k3OiIHe8o/35wJkFAwEOE7ewFS/V24E/74BOY+aRdozcSSsG8fhRMhxaHLAMPjXT9iLA2uiGK8umCxEy5jqS7RrVjJw6eRJYB3MvdKe+grbiHudi14ViwCqJAqKHon6Lkxo2usVHf1pSXgGWiYvyJFzXgE8Y84/08rB7bMC8/3VCYgJ6twAFn2NMCEOx0dFEa0J9bOe1h1mlR4TJjIHzv9v55jL4zDZNEzZCC3ztH5aNaFfeRcNNtiAcTvZys6eDjQRnx3A/aVRJm1PF62g5nHkLJIXdsKuo3zsx4cuxlDahsUcjwLuWtA9QJx4bfUsKK3o/EwW01Mjt3kKhBNqzXb0D35uAuEO6uXrg2sy4CU+TodCH+qDfiWVAGYv+h0YHX2n4pdPfvqew82r1sUM4vwzSocZsS3ydLwqIr/zACv9flMIoMRbZTUErwQNxs1Tfn3e8BRSpFNSMRVs4sUIKAqfmVba47eGCqywmQBp/JHmgAFFhiIgH/VRcaCt+XSiuuvuEHxjSMUAeJy/ftL9feNOu9zCfFWgkP6eYufcfJwkZol3NbZRCA/bWe0IxgsWwAfZ8/Y4/OGWKo/MFwX/eBn+YdoM+m7Xg6YWHY0kric= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8030e97-e752-4cff-3aa3-08dc4d9a2f30 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 13:39:39.2597 (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: tyN0d/A74pLbYrmm/0WIZMXu/4/cG2rzt8veRrKWJvqxCrNGjj4nvAHU0I/0w/ArGdyOyHe/ZuwrcdaefJAC0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4749 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-03-26_06,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2403260095 X-Proofpoint-GUID: zXu65VB0agSt0MgYp9sgV2J9-kwlc_cD X-Proofpoint-ORIG-GUID: zXu65VB0agSt0MgYp9sgV2J9-kwlc_cD From: Alan Adamson Add support to set block layer request_queue atomic write limits. The limits will be derived from either the namespace or controller atomic parameters. NVMe atomic-related parameters are grouped into "normal" and "power-fail" (or PF) class of parameter. For atomic write support, only PF parameters are of interest. The "normal" parameters are concerned with racing reads and writes (which also applies to PF). See NVM Command Set Specification Revision 1.0d section 2.1.4 for reference. Whether to use per namespace or controller atomic parameters is decided by NSFEAT bit 1 - see Figure 97: Identify – Identify Namespace Data Structure, NVM Command Set. NVMe namespaces may define an atomic boundary, whereby no atomic guarantees are provided for a write which straddles this per-lba space boundary. The block layer merging policy is such that no merges may occur in which the resultant request would straddle such a boundary. Unlike SCSI, NVMe specifies no granularity or alignment rules, apart from atomic boundary rule. In addition, again unlike SCSI, there is no dedicated atomic write command - a write which adheres to the atomic size limit and boundary is implicitly atomic. If NSFEAT bit 1 is set, the following parameters are of interest: - NAWUPF (Namespace Atomic Write Unit Power Fail) - NABSPF (Namespace Atomic Boundary Size Power Fail) - NABO (Namespace Atomic Boundary Offset) and we set request_queue limits as follows: - atomic_write_unit_max = rounddown_pow_of_two(NAWUPF) - atomic_write_max_bytes = NAWUPF - atomic_write_boundary = NABSPF If in the unlikely scenario that NABO is non-zero, then atomic writes will not be supported at all as dealing with this adds extra complexity. This policy may change in future. In all cases, atomic_write_unit_min is set to the logical block size. If NSFEAT bit 1 is unset, the following parameter is of interest: - AWUPF (Atomic Write Unit Power Fail) and we set request_queue limits as follows: - atomic_write_unit_max = rounddown_pow_of_two(AWUPF) - atomic_write_max_bytes = AWUPF - atomic_write_boundary = 0 A new function, nvme_valid_atomic_write(), is also called from submission path to verify that a request has been submitted to the driver will actually be executed atomically. As mentioned, there is no dedicated NVMe atomic write command (which may error for a command which exceeds the controller atomic write limits). Note on NABSPF: There seems to be some vagueness in the spec as to whether NABSPF applies for NSFEAT bit 1 being unset. Figure 97 does not explicitly mention NABSPF and how it is affected by bit 1. However Figure 4 does tell to check Figure 97 for info about per-namespace parameters, which NABSPF is, so it is implied. However currently nvme_update_disk_info() does check namespace parameter NABO regardless of this bit. Signed-off-by: Alan Adamson Reviewed-by: Keith Busch jpg: total rewrite Signed-off-by: John Garry --- drivers/nvme/host/core.c | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 943d72bdd794..7d3247be5cb9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -943,6 +943,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) @@ -957,6 +981,12 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, if (req->cmd_flags & REQ_RAHEAD) dsmgmt |= NVME_RW_DSM_FREQ_PREFETCH; + /* + * Ensure that nothing has been sent which cannot be executed + * atomically. + */ + if (req->cmd_flags & REQ_ATOMIC && !nvme_valid_atomic_write(req)) + return BLK_STS_INVAL; cmnd->rw.opcode = op; cmnd->rw.flags = 0; @@ -1937,6 +1967,23 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl, } } + +static void nvme_update_atomic_write_disk_info(struct nvme_ns *ns, + struct nvme_id_ns *id, struct queue_limits *lim, + u32 bs, u32 atomic_bs) +{ + unsigned int boundary = 0; + + if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) { + if (le16_to_cpu(id->nabspf)) + boundary = (le16_to_cpu(id->nabspf) + 1) * bs; + } + lim->atomic_write_hw_max = atomic_bs; + lim->atomic_write_hw_boundary = boundary; + lim->atomic_write_hw_unit_min = bs; + lim->atomic_write_hw_unit_max = rounddown_pow_of_two(atomic_bs); +} + static u32 nvme_max_drv_segments(struct nvme_ctrl *ctrl) { return ctrl->max_hw_sectors / (NVME_CTRL_PAGE_SIZE >> SECTOR_SHIFT) + 1; @@ -1983,6 +2030,8 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; else atomic_bs = (1 + ns->ctrl->subsys->awupf) * bs; + + nvme_update_atomic_write_disk_info(ns, id, lim, bs, atomic_bs); } if (id->nsfeat & NVME_NS_FEAT_IO_OPT) {