From patchwork Wed Jan 24 11:38:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528982 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 9C1512BAF3; Wed, 24 Jan 2024 11:39:36 +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=1706096378; cv=fail; b=PVR84Bxfw883rR8qfLkAPo2LwG0Q1BX08QfCgMRQP+OsNk7dMCF0cRjmckO5o9xz8uwtc/6cgD/txwNjmY8/QqS4jx1c4d3OG0q9TKpjOTH1d87WiAZAHGbgk5ZzACk1q6Ka7YLsexzF0uWdubaGleDVsGqstENZMMDWVBO++k8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096378; c=relaxed/simple; bh=0ZZ6adVNyZS4ppIAJ2f3Xq2GD4ta+Q+ckwS3kHJykFQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=NwcctGZ9pNRD+xG3gMguUDNNln5PS0xdH5b6y7OIOvKQ7k+fNJYtV+ankJrM3Z3kxWI28PVl9mDKgDs468qTdm/bsGFbsrfPXkf2ppYLoNwV1OGqdzpBfzar8yakYGDApQGqsTpjrjURSXUDUMqnKzQh4NP14r1GIS9bQaKE1/g= 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=bSaiF746; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=QoOD9vtu; 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="bSaiF746"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="QoOD9vtu" 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 40OAwtp4009439; Wed, 24 Jan 2024 11: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=UleFiMjebQfomIRfcZwKlfaUK4esV8jzRO6dV8lg0Iw=; b=bSaiF746R31HsqSclpbhu+fWKajkYBgwtyDqYcq2WGPe1pIcafn/G78Wxv7CO74n0lFw 6w4vI+vDlD3+iSgancl8pZuP+8vX8xekGYu2ADdyB+wW3s1F1RYqtsZ6F8l0Zpv34QXS OXthLx1G0BSOtREEI5scpRP+iq8XRTGFM166YZwSBnw6OJscJDUghR1ZI5hzRp9OLVvI TQF7KwPL5ci09n8fqo05nX3zniJmuvAqbGb6+yiuKWAo/mSSjfo8Cq5XSgQVY69yk7uQ 6ABDbYWRjGj5SIXH5PqxFlBoXCth8LJ4MDe0esrmRD9lxSylte6fIVJJXjIBWMzcaqNP fg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7cy1tue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:13 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OBOr76040836; Wed, 24 Jan 2024 11:39:12 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs316wnqu-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZCHao/KytGaypy2vijr8svLXJ4ieujF33R1SscVuqXu1lAZo7ARW585VAAEot30jl0wZ5KwK7H9v80bEkj0drbUrVuNfjvVc/iKuUqp+VpKUBl11DMeK5zzXulmZ2pR0oItvYLvYxTKz/2n2eCvGoTMEkkXlx53DJSDyq874x5kEjvXr7IKsgOn8sInGlwv5KaRbKb+qf7RaGbB/yQxkPAJoRyeOfCmstPXLngHH+tX4Hz04Tun/h+QYh1Eqw+6CmDRLCLeYFDqILwT4yigWgA0NpoFoCre0hiJ0/5IbfAvIA8g8wiGhKAuoKk6bmoT8JukoW/RaP2nNRDJPbmsRJg== 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=UleFiMjebQfomIRfcZwKlfaUK4esV8jzRO6dV8lg0Iw=; b=gISYTQmaASmSSujtw1Naay9hZPDv7QZj3fF3Z7JfV6qk1GpG1uJ/e0J2cI3tuXRoEAHjgclgmXv0ux52R9FYY/KoWQCOfVnJlLW/Yh5LhMDIriU/3ZjP/USJBBek9TNY+RTY1FdKgGVZ9jhShDjDZepZ10sYQkZCfIb1do/C9HVcUbw3R7LGJcYQXuPshT9NnRKoSiPzA40SBRtGaFE+0R/0/UDXq1s7qxN2ZVNjInXy7U4Tu47jsrIKNFoAo23KYf5F/zBLufG/b4PYDlHOjReoeH8T04QagcR1zev9x2QVgCQrsIz2Z72WhsdIQcrQVPOb8613UdZejDf/5emqog== 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=UleFiMjebQfomIRfcZwKlfaUK4esV8jzRO6dV8lg0Iw=; b=QoOD9vtuSuWdL6s+A8fAEhZvwzEl4f0kEnSFB0KC75xNiJk8iJxzD5p4fuGefIeiYoLP9dm/ZYxXJkiF2O1dpGXM9budjBVRtRDs+PcGZ3pZqVp0MQszfbSBChPip90vikySquwADr+TZ1ePoT135X+Pf0jR0dsuSeYisA98NFM= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:09 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:09 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, Himanshu Madhani , John Garry Subject: [PATCH v3 01/15] block: Add atomic write operations to request_queue limits Date: Wed, 24 Jan 2024 11:38:27 +0000 Message-Id: <20240124113841.31824-2-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P221CA0001.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::12) 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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 48abc66e-d99f-4f52-0e2f-08dc1cd1142f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xD+TvSFBLPDdtQGup/SD3f+/lRXD4/PNmbJd9Z3qN6fj9BtwoQ3Bk4fmkuZ9sDYEoYUbRrK6hoykRfdHdfA3zRUrSl/D519HtWtHQLXbueo98IJPtfTcvds0PAyQUrzMaNfBqehTOaCkixZRrv1DKw9WjlPov1ZYN24n8FgLpxbN+y6oozvEmkL3ZibXVSPE6KrgwYWj0/ld+tRpgYUSK4iE+wo2Ywk1+g5CufzoA50ScFfyTdZIIogrNBE93oJhR8ijmCghfo3qVThC4kzO7iy3l2ECiwC6ZeAsp5cqtQ+gpGs4vrtozyeONxHOb+3Mjhh9br/VjmlCHoW0waASK2UIFZ1qiY2mHnp0Q60pMMKiJae+zxqTFMt3lF+OXt7V+CyxqfrRq7Igd8B24ZYt1cSsoQNlC6mJbxHpMaebQ1kADl4qtW8Omm+AR1F1aBGukVedSm7l2wtgTmuED2PfQHHFFl2NnUnQC9KEtMU99F4fJmrs9nyUzNyBI4FZcSrNdnjz3Cg/+3ZKjhOYnad/vrEtsZWmdta+1Vsnfvl1fDL2C/w9wILD6gcXBGHgZN02Iu34etjp+Q3s9NagiOYydfs+cukxh2l1aX7icnpUe1c= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(54906003)(66476007)(921011)(30864003)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(966005)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vi5/9DoU72cO1vxN5onlt6SGftCOof3uLAxO6t0dcvWPyt0SFLpwlaQNnorKYBFFVsqAdTObjFbEeDxy2nkJHZvjIGT+FK2u4uirbDm9KPAE2l+2QnIkSF2xXW6frmhN74I6ILP5zhnw88dfPgdbh5CwVA2VqDU4WCoR69x8KH1Sc/UtihQlbMSF8iKZ/mnxTiLUqZKzZYMK8DCeA8TedSlKyE6v69gIcePC04rK8XvSoARj/G1P40dxUFviPQgrNa4ZTqkTR3gpD6PmB5m3Swa3cd18EI/DZDmgR7/weojNdEPiSGKfjLf/r3HTicni0slFA3J43MyJ3wycDHCLMLSYszg14s9SzkXsw9Jo8ViGEFE0G5dsQz5q9alzugCcLFz0PKMYxjAEPU0boFa1rY2WPkoUawBc1o3x8LnXu/Cnq9BiPuedpu091w+sVlQwFaU80uKToLTefsbyc2HYeL2pm+os5OmzksVGhRYMSJVYgmguESY64geMuqqhj1ACaIzT2DapkICa3fDN4v3IEnrpATPWCcDwP8Yafhk8eqH5WQnnXzLEwa4AbxI02cgtsuYB2RlpiKujConUDQg1WEBAcnoBZXbwWs6OetMuyECj7Wywzw56BD98LmuE8R0BqCAH4Yndnri+kb4e01eheLrZqhs/bKqQRWXR6Cl7NStZThX4HEOhYzzBM2CvgzXkBNfWNzbIKakAq0Ze5BtG8TjUOBoh1AmmW18ymm1lES2Y8rhXPHivixa6Y+GRHCPgCFJKPnk0+8ADTdDoUADEpChS2lP82qfq2N/c/J9o6I34gD0O1s2dxCpU9nqPARjq/0etmTr2CjGQ87HGoufZr4cI/lHIzQlDRTWUg/2d1JqahqSQSJ9KgnQmciGDdoEwjKKDTOTCv7ee/fbb5KwKzIiFIpOo4na9AKHemDazkFu6Tsa05y6nrFib/xKyTVzq77IV4GeZ3ktSgsDUUuIesL4M/05g131aXcDP6vlBN7k3/dwrk1h8mo9dDqi99DibePY4qW+zatoUlH27VYsOjj2MMF6WzwQ49rn67YfUGo6EVi1GHxmZQatD08Ox7FYCvuDLlz+qiNMqoOpZ5EGsAx9EZPUwsuJBDYcMD8tvh+4PAlhM+ADv3wisbM+GsfZIPW5CK8/xyWEzYemcMjyuXMUUQElDcWY+siMFDqM9kZoWpvsrD/wU05APCDyJTbuFnHNzz/L1nvOftCMthcOtoNMIWQB3ArjumaQyPpqpury1ziWN6jeM5wY91iFttkV9+U7xywrSzRmVedwvzBjZ8EhobyF8X50Tm+b75gDpmJCHhtVM9OWgLadk9zAXy+lZoD956tiCbvitdDczjr52vKrZNvApTEdnBwZhLWM4XywN/KEa5xAhv2B/hMo+xSYVmg30x9jo6ppdA/xKCjO0M1ubF4AJZfxuoGLfHNEI0UbLEO1oVf/t/v3CKu/F4Ln3UpUrNSYCKPW5EeF1lJxCwBT9ElqXjFsAHH+GACGVt3tV96Zn2ElB2Z9MxX8k+mfMpT/iuVtuWDV2JGmL+Fl9XGyP+5WMLL6AGZfg/N7j9cp7KHIrXuHe7A6onK+0VLpIrfDC0c7StfgU1h0ylpuWHw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 3p4wLupB2gE+6sF16GcEhZxI03M2/WOn2eGf5czNkX0O3g2yznd6z68JaESKP55QbIQSwJeTb+JD19qjfL+5cM7W4mF4OPmXLLXT5Ces+jnB5WffEA3DOE6LTPU0LwTcw1ioRcq55ZHsjquhyOrIQlwVBPij86liGsBnJCkyrr48CS5wC3ew4/LjCxDOBUEP1NEs36XPcHiImljz2Vtws/hR+8EZahGV41NLvt7HMYVsQ8pB6dv+qVUIRLEZa7MssaG3/aehBdJK0Mw/rUIKE8Uonyv1hjYPh+qV87wHmOXKgHNJT0IstqgDDHftYxe2ZzfqrmTpHf/o97GV/gFmyQRG1mIn0RS4dckAaC3jRIlUX7et+QNaIqiHOqqqmb8mmX/XjPbWTigIJL1J6CaQ526GO6TR/7idgdYYWfJ5xtZtymLwZ5H6WnJiNA1zciqZJgJqyUUbkryImgp5jxFN229WdYMV0beq8SiOptJmpYt2pXSyRpHY5NT2z+OWROsxhI7f4jNMsGWpK1TFoBVrVcEiYSZGhfIHlyrMJF92ZpXv9LUBO7SEOEDcj+XeL7iDga8SXHRrJfahuOLMhx8pSuC2EqwQJrHGOVA6RHFCqVA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48abc66e-d99f-4f52-0e2f-08dc1cd1142f X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:09.3229 (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: sMUtCWLC/DqvF6+3Xhh/66FYL9A4emukv23pNBndygc0haSQrqdoIbqSxmuilHXf92TpnXhUyN7kUBoIZvJBWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-ORIG-GUID: y9_Mh8uzZZ80VPW2YXPt0LXovJwFl4Z_ X-Proofpoint-GUID: y9_Mh8uzZZ80VPW2YXPt0LXovJwFl4Z_ From: Himanshu Madhani Add the following limits: - atomic_write_boundary_bytes - atomic_write_max_bytes - atomic_write_unit_max_bytes - atomic_write_unit_min_bytes All atomic writes limits are initialised to 0 to indicate no atomic write support. Stacked devices are just not supported either for now. Signed-off-by: Himanshu Madhani #jpg: Heavy rewrite Signed-off-by: John Garry --- This will conflict with https://lore.kernel.org/linux-nvme/20240122173645.1686078-1-hch@lst.de/T/#mf77609a2064fe9387706ce564d8246c5243eeb99, but I will rebase when that is merged and I assume blk_atomic_writes_update_limits() will be merged into a larger "update" function. Documentation/ABI/stable/sysfs-block | 52 ++++++++++++++++++ block/blk-settings.c | 79 ++++++++++++++++++++++++++++ block/blk-sysfs.c | 33 ++++++++++++ include/linux/blkdev.h | 40 ++++++++++++++ 4 files changed, 204 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 1fe9a553c37b..ac3c6b46f1a3 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: January 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: January 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: January 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: January 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-settings.c b/block/blk-settings.c index 06ea91e51b8b..11c0361c2313 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -59,6 +59,13 @@ void blk_set_default_limits(struct queue_limits *lim) lim->zoned = false; lim->zone_write_granularity = 0; lim->dma_alignment = 511; + lim->atomic_write_hw_max_sectors = 0; + lim->atomic_write_max_sectors = 0; + lim->atomic_write_hw_boundary_sectors = 0; + lim->atomic_write_hw_unit_min_sectors = 0; + lim->atomic_write_unit_min_sectors = 0; + lim->atomic_write_hw_unit_max_sectors = 0; + lim->atomic_write_unit_max_sectors = 0; } /** @@ -101,6 +108,20 @@ void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce bounce) } EXPORT_SYMBOL(blk_queue_bounce_limit); +static void blk_atomic_writes_update_limits(struct request_queue *q) +{ + struct queue_limits *limits = &q->limits; + unsigned int max_hw_sectors = + rounddown_pow_of_two(limits->max_hw_sectors); + + limits->atomic_write_max_sectors = + min(limits->atomic_write_hw_max_sectors, max_hw_sectors); + limits->atomic_write_unit_min_sectors = + min(limits->atomic_write_hw_unit_min_sectors, max_hw_sectors); + limits->atomic_write_unit_max_sectors = + min(limits->atomic_write_hw_unit_max_sectors, max_hw_sectors); +} + /** * blk_queue_max_hw_sectors - set max sectors for a request for this queue * @q: the request queue for the device @@ -145,6 +166,8 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto limits->logical_block_size >> SECTOR_SHIFT); limits->max_sectors = max_sectors; + blk_atomic_writes_update_limits(q); + if (!q->disk) return; q->disk->bdi->io_pages = max_sectors >> (PAGE_SHIFT - 9); @@ -182,6 +205,62 @@ void blk_queue_max_discard_sectors(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_max_discard_sectors); +/** + * blk_queue_atomic_write_max_bytes - set max bytes supported by + * the device for atomic write operations. + * @q: the request queue for the device + * @bytes: maximum bytes supported + */ +void blk_queue_atomic_write_max_bytes(struct request_queue *q, + unsigned int bytes) +{ + q->limits.atomic_write_hw_max_sectors = bytes >> SECTOR_SHIFT; + blk_atomic_writes_update_limits(q); +} +EXPORT_SYMBOL(blk_queue_atomic_write_max_bytes); + +/** + * blk_queue_atomic_write_boundary_bytes - Device's logical block address space + * which an atomic write should not cross. + * @q: the request queue for the device + * @bytes: must be a power-of-two. + */ +void blk_queue_atomic_write_boundary_bytes(struct request_queue *q, + unsigned int bytes) +{ + q->limits.atomic_write_hw_boundary_sectors = bytes >> SECTOR_SHIFT; +} +EXPORT_SYMBOL(blk_queue_atomic_write_boundary_bytes); + +/** + * blk_queue_atomic_write_unit_min_sectors - smallest unit that can be written + * atomically to the device. + * @q: the request queue for the device + * @sectors: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_min_sectors(struct request_queue *q, + unsigned int sectors) +{ + + q->limits.atomic_write_hw_unit_min_sectors = sectors; + blk_atomic_writes_update_limits(q); +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_min_sectors); + +/* + * blk_queue_atomic_write_unit_max_sectors - largest unit that can be written + * atomically to the device. + * @q: the request queue for the device + * @sectors: must be a power-of-two. + */ +void blk_queue_atomic_write_unit_max_sectors(struct request_queue *q, + unsigned int sectors) +{ + q->limits.atomic_write_hw_unit_max_sectors = sectors; + blk_atomic_writes_update_limits(q); +} +EXPORT_SYMBOL(blk_queue_atomic_write_unit_max_sectors); + /** * blk_queue_max_secure_erase_sectors - set max sectors for a secure erase * @q: the request queue for the device diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 6b2429cad81a..3978f14f9769 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -118,6 +118,30 @@ static ssize_t queue_max_discard_segments_show(struct request_queue *q, return queue_var_show(queue_max_discard_segments(q), page); } +static ssize_t queue_atomic_write_max_bytes_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_max_bytes(q), page); +} + +static ssize_t queue_atomic_write_boundary_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_boundary_bytes(q), page); +} + +static ssize_t queue_atomic_write_unit_min_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_min_bytes(q), page); +} + +static ssize_t queue_atomic_write_unit_max_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_atomic_write_unit_max_bytes(q), page); +} + static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *page) { return queue_var_show(q->limits.max_integrity_segments, page); @@ -502,6 +526,11 @@ QUEUE_RO_ENTRY(queue_discard_max_hw, "discard_max_hw_bytes"); QUEUE_RW_ENTRY(queue_discard_max, "discard_max_bytes"); QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); +QUEUE_RO_ENTRY(queue_atomic_write_max_bytes, "atomic_write_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_boundary, "atomic_write_boundary_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_max, "atomic_write_unit_max_bytes"); +QUEUE_RO_ENTRY(queue_atomic_write_unit_min, "atomic_write_unit_min_bytes"); + QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); @@ -629,6 +658,10 @@ static struct attribute *queue_attrs[] = { &queue_discard_max_entry.attr, &queue_discard_max_hw_entry.attr, &queue_discard_zeroes_data_entry.attr, + &queue_atomic_write_max_bytes_entry.attr, + &queue_atomic_write_boundary_entry.attr, + &queue_atomic_write_unit_min_entry.attr, + &queue_atomic_write_unit_max_entry.attr, &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_zone_append_max_entry.attr, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 99e4f5e72213..d5490b988918 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -299,6 +299,14 @@ struct queue_limits { unsigned int discard_alignment; unsigned int zone_write_granularity; + unsigned int atomic_write_hw_max_sectors; + unsigned int atomic_write_max_sectors; + unsigned int atomic_write_hw_boundary_sectors; + unsigned int atomic_write_hw_unit_min_sectors; + unsigned int atomic_write_unit_min_sectors; + unsigned int atomic_write_hw_unit_max_sectors; + unsigned int atomic_write_unit_max_sectors; + unsigned short max_segments; unsigned short max_integrity_segments; unsigned short max_discard_segments; @@ -885,6 +893,14 @@ void blk_queue_zone_write_granularity(struct request_queue *q, unsigned int size); extern void blk_queue_alignment_offset(struct request_queue *q, unsigned int alignment); +void blk_queue_atomic_write_max_bytes(struct request_queue *q, + unsigned int bytes); +void blk_queue_atomic_write_unit_max_sectors(struct request_queue *q, + unsigned int sectors); +void blk_queue_atomic_write_unit_min_sectors(struct request_queue *q, + unsigned int sectors); +void blk_queue_atomic_write_boundary_bytes(struct request_queue *q, + unsigned int bytes); void disk_update_readahead(struct gendisk *disk); extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); extern void blk_queue_io_min(struct request_queue *q, unsigned int min); @@ -1291,6 +1307,30 @@ static inline int queue_dma_alignment(const struct request_queue *q) return q ? q->limits.dma_alignment : 511; } +static inline unsigned int +queue_atomic_write_unit_max_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_max_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_unit_min_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_unit_min_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_boundary_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_hw_boundary_sectors << SECTOR_SHIFT; +} + +static inline unsigned int +queue_atomic_write_max_bytes(const struct request_queue *q) +{ + return q->limits.atomic_write_max_sectors << SECTOR_SHIFT; +} + static inline unsigned int bdev_dma_alignment(struct block_device *bdev) { return queue_dma_alignment(bdev_get_queue(bdev)); From patchwork Wed Jan 24 11:38:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528983 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 BF1DC2BAF9; Wed, 24 Jan 2024 11:39:37 +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=1706096379; cv=fail; b=M+ALk0xaeCSBwQxOoS3MImjy1qs9LWupfqovbFHAv5oiS6oRM5HM7KfPVlxaS3b1Ddd1OxnK3wKycHWMqFF0Ngo3rh5ZIfkjSsrdSNwdvNKFn8TYjQTAsU+Q/hqMmz7rU1yH4mtCW4lsIkVSEwhLOim25Qw2kyxvJKWyWxfoLUY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096379; c=relaxed/simple; bh=DoOIoMDRyrJq6/g8yMZfQUMtlZ8TM8Kve6Gb9VKf7yk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=KqbBVyjjShix8X7SwxGhHEcqaI9UHAfg5aSPomBjVMbH5SEbJIZmHpyhZz7z4wg+0JRSO5S7iuKTPYWxiFsb4iPBT0aMK2NingjbyGgat3e+eM5etyIbyL5mnHsQJpiofmUnF5Khz15f+LoHrFrNhRXKMpG/eTx6az0gOIWHtjA= 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=QP9OpzxD; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=qz0+jyWu; 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="QP9OpzxD"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="qz0+jyWu" 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 40OAwiDg019763; Wed, 24 Jan 2024 11: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=+uSIUXjANZFukgMeeMVkRq+TTUtGdQJp3I42PgVd64w=; b=QP9OpzxD5vzokSry2J7zk4QTQtMGfA3biq5C8IK8FpCPZzoPm1oU8FkomqG4oc1dICJ9 /0D65cIKGiiNH39Qz7yBwcX3kSwJK/FDdFpmQXpp9PUAcVDy1Gy8VBYn5/F7pULOKB0p MGRrSQsu2E3PLOSVFqvnfVQfqriZdC3Lel0DtbQqKDqD4hGDpUSVcLlSxOPOOb/7X+4a +xqSasBOXjQOtnn8yABu1gAgJwV5YY3FMgLMw9W5xHWugmzdFucO8ITVQr19D6uLCeBt k877ICE5+0vYk8t0GiXoYcqdSBJLjHOYV9acZMXHMmUTCw2r22It3k4oj8Mpe5QVyF5p vQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr79w2600-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:14 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OBOr77040836; Wed, 24 Jan 2024 11:39:12 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs316wnqu-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=koaaPhm+BXKhX0GoWZTVs7XYPhR0sNIDaHqem6jDcrDO36o0a6hXUfBWSxPmwHIEMUWnPDPiF5MYk3M5lensTEa9uEtn21WpGhI0BGAOQ0U6nHZQFulRFTA9oPphJHJ6YSlgsDibGZDC3EmwD680UeqGB6uoSa1ZD0MP0Xawyyljd7hnBXlK2MKOd2mWpDGdK1pKlAnf4OqW8AoFtUfU6Z5nCOrsLFQ45WgRGQdMnaBYJoBflF2HUF2Xo5sNdEFuuDRO7SzOIX6o+CgcOeGo8KwZVkq7ESdgqY8oTn1TNi0y59shGXfTGrNj3df32hyKhnhFkoV2U1+oieljpU1hQQ== 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=+uSIUXjANZFukgMeeMVkRq+TTUtGdQJp3I42PgVd64w=; b=gah0Fe7Lr1WbKE6pdwrD/Saywq9WfG2Y5AlNPidMbGaj4rnrqZaT3hoQxn5BBdfXbr/OwiNnqNREF85j5D8FkzBb+ZGaaG8VKJazY26mnIljw+IAyyzEyxNsxGIK4OZbRkdZQ1EeKBzISIeQt/uT2Yv0LIGdlSPQHQzBX3Jv9lN8g1EOv02pUqsX2Mt4JRSwJAyxUZcmOpIZdQsfxNzjHuZDlcyKms/Bp25NwC3QMDN8EA0QGYV6buxVrMmaJZE6MBncv4FXn2OE55r/yq36v3h9DZn2pwGHjjnEJAolFETKFTkbL/bP/WitZyhljJ5C8NpnM0EYXVzjq8aE+qg6vA== 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=+uSIUXjANZFukgMeeMVkRq+TTUtGdQJp3I42PgVd64w=; b=qz0+jyWu8/UQWNkstq2+Qt7BDvfZYfNv+GZOkmLfsTFLriR3tvG48M48EUiojZbaN+alyHmST70GnHhzIePXKKcnfuBJU1hu6IDSiKSg/LxdvmvbU7FEKMoM7VE0QZEo4TZtsUB1DhU4grrvhG/TT8FaXqo/ax6Z33/AjrSF6Po= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:10 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11: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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 02/15] block: Limit atomic writes according to bio and queue limits Date: Wed, 24 Jan 2024 11:38:28 +0000 Message-Id: <20240124113841.31824-3-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1P221CA0004.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 1470a19a-4204-4580-242d-08dc1cd114f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EVf722S+2N5J0cadwaKUqAZoxAovU88dKdrNdThMLwqOJonZetvaNQEbxVujOz5buGsC/yGoVvS13V1dhDwyCaXoL/JgkXT53hFGSacgZd0w1arwd4M5ltIs4E1BbgCoDgd3Cii3m7MFQMHncYPpagK/2COfY0HA/LwDlvCc2N2AkIPOPb8GD0bYdGeLJDFrHN5joxgGLyMheJ4OenQY7Q2nZu2HPl6wDisaPTbxhT/yD9OBJzIZafypu2txR/w4QpUl+olfMEVVDI1G5xRwV/SfI9N2nsAPUC8tJHIDHY+BspqRhLjbgTnUkaI6OEjExWwTr4YK7cAaThUgohMLgu4n609K5Prr9tshNFrWorn2zTNFpzotmMy9cq/fuiDHo78yNXSVLD9rpU7s40d4HdCkwEgsHraQJF+RuTUyrjV8Gdas1TQFiHKEpQyd9+TtKHhEYIQegafCCBrBU5rY+yBbMrTfILuIGDe066erQaBXryjw6GNAf0ZNrUqW2pceh83op9an0+B23WdlWu8Vf953LhfGjqoN70dsfAdKvc/IwdS4euDVNNaZhh2lCrOiAKTPmMYFNef1e8juy4ZsSBqQx6tY8ay4DjM4kjWaMds= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(66476007)(921011)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YILztSYGQnrkzNH58UozykSyR9A/SSFK3p4PbL93L9j4OmFPw7h7K+f6TS5A42WrwUBh0rkRi/2pXsUGkHFNwPX0u070oOLpUv1ZxCmsZdqVVHfzTnUgUaLewpJqd6aWVrc4Hyy4Q6VJl/5LDy8BezJalihGr7FvGOru+DmjsEYliS1bgnkxELGWDndG+jKpYdTi2tDzFkiVYRrWc8LQkl3TUy/4/H9K31ox+r8lffQzGYg6WF28s80/gjQpviF8VKrPOLcOYFilmFh0uHxqtC5BUi2Uhw4vt+BpS6oxLCr8o80qXq35tF8OSgd/ZO/9lVo95ZTxEFNsUMJyZZSW9qV9ihUZ2xu7z8gTqjEijuufXQ2WJKVZmObIyQzlxsuH5sQskDgzSs+L20h3Xjyeeb1zh7Z26A5WFCIq+DKIwIbU9s+WECxPG54LRVUuBKD/Lb9aYw+0jYsHeJ+iH/WDk+VNKbjsvt13Zd59t2DXIKZXQYagXVVx1Y+KeMGYtQYmEe/Pu1k8cWM0TgOjZh5wHuvNlOF50gdh9cz1tIPmdQU46YsfqvP+ob72RWgIBpsa8/5npadpbpacSKpZN9dI5vb5e58MoAGu6whevpTBRZRslhdK0PxXnhfyyV47JfsjloaPiTKN76ehAB94y0UB+DKWsVdEnOw+eqjRfe5ya3gr7zneb9pGMug73Kg+iEKCKpeWc1wfyszOnHx4GwBzTIwrAvRG6OWwiTrrudhcHAtuGwGj99o2xq6/xt0HcbjvgIsnvOBrPHdRfFZz4SzQzwMH5oA4mB5Yyj4isuZR2fQODnbqJFuhKugdG7QVgd+bSLe2jYFDMIDLz6v2H5zj440l52pB3ppqmUnZXEqxfUoFTdU96wbRdNyRV+RM443isahYnPrQVhyUXGRl1jEdLmcmzXq6ScjuMdmFjupKSHQK4PE4n6APrIHhCS0dIAIwkKx5yDgyNQZqnRjMMMA/cE5LLbLT30VO4T4fbN7H5Hpd8mEBfctkHEVKs5nZcyeWYHoRht1N0i07ycwNBy6icUyRsSNpCGar/+ElpoVc17fo5w/d6B0n7WR26z/HloW5m7M9IBRc3dcAMh/ZhcQ/7My68awJEP/cCHFFgj5XWCKK4fKDaQsQM8Hexz1fnzi1L+1yGHcZZ1Y7VqdShGJu1pivAnsdp3n+SuDk4wnU2TZ25bVfRsZxZKUI6dNwBCTjdaA/Cq86cHl964CR80sFdRM9fUYYtYF4ludnF9KssVJStDEqgw3MromO8nCjFaO1lInpkSHHkqMefr7ZgJB7jpBMqzB8Ca+yGBPO8+nFKgycxZK5rPEYLUXI5itqx0dga/pGQxjq/tvSdFG6OAR3qmpuD3QdPbAaYHa+WqaHm5UjGHkIBuZuu3F+MNKdSZ4+VVJzsLRYfE4WrZmOrnEHyHdKIVzUsJip8uTciNMN+kUbnWRZiuIk0TAyXYeuYO82FZVwI6TzKE+Kfv7YcpEoWmZj+8MyFyOwHB7e6Ufjmf4qmUTbejofmWC7WcSIYYd5i3+kouaExwm51XjtaNNaCqRIfvQSZ1f+hYk0EntKIU5V9JKSNXfFrHc+3ISkeS1Y7bHIcDt6ySIIFepEI08WgA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: kD4EBZqYiKW76YIUlKxLWPl19dD31OHHZ1p+q33iYhX7uqxf0zr53rcrApGnrZwG7LP/UZIaqlq+yh4viQMsvLYKI4zyMqJz2Tu36O5OxaxUSmXXhU4uhjSKP2nIEzHkyhtHUSCHaPylwmBxt7VCKkS9xUbMSjeucI+t9tYTD7kg7ngxuF6btBCP808/zD72uyEFc8GYMPXj6T88S3kam7Rg/uSXrNr6N9yn5sqUI1GLYxYFZ94Wl7/6JagB5jyrqp+lWcylv6eD4AKd1Fi3E2FTslX1w7twKkETu/lZJQezI0mtUxPvIjWmfD/ZAv2sJt2YDoGz9bU2FviX4nPiO8mOGzrrtmeI6KLNP6zyjGidx3wQjqTXe4uS23C/U14nCV6uG1KodO/qRrsGK2ADf+f9ItsBDMB/Lq76RM2aYHIH4sePlMx3DkKSFzSCUpfEG53ELMrfkIXNJ4EbWyGl7T/Up7Xnkl8lXWdIpsfjO7zkqU4p2DQrQfkB+W0nEDr/9n44nNvveIKsLINLEv7d7RTKJpHvl1zeI5qwrMBOzjo0IQpvVNihKogtjsF1RZHgxra1+KxjPgUJ9Gnv65jlWLQ3x05vBVhItOM/2BDqfAA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1470a19a-4204-4580-242d-08dc1cd114f7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:10.6034 (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: 4mLAtLTPZJD3VbvzoFllLIR9mEVdNT1xTNtCtPrseAgJMnDDxD/jjvRoG0d0pe0e/sLHI6GAE5fnEjk0HWBmjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: 0dgEDptt4ip3xmm9QzfOK14mBdPqtszO X-Proofpoint-ORIG-GUID: 0dgEDptt4ip3xmm9QzfOK14mBdPqtszO We rely the block layer always being able to send a bio of size atomic_write_unit_max without being required to split it due to request queue or other bio limits. A bio may contain min(BIO_MAX_VECS, limits->max_segments) vectors on the relevant submission paths for atomic writes and each vector contains at least a PAGE_SIZE, apart from the first and last vectors. Signed-off-by: John Garry --- block/blk-settings.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 11c0361c2313..176f26374abc 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -108,18 +108,42 @@ void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce bounce) } EXPORT_SYMBOL(blk_queue_bounce_limit); + +/* + * Returns max guaranteed sectors which we can fit in a bio. For convenience of + * users, rounddown_pow_of_two() the return value. + * + * We always assume that we can fit in at least PAGE_SIZE in a segment, apart + * from first and last segments. + */ +static unsigned int blk_queue_max_guaranteed_bio_sectors( + struct queue_limits *limits, + struct request_queue *q) +{ + unsigned int max_segments = min(BIO_MAX_VECS, limits->max_segments); + unsigned int length; + + length = min(max_segments, 2) * queue_logical_block_size(q); + if (max_segments > 2) + length += (max_segments - 2) * PAGE_SIZE; + + return rounddown_pow_of_two(length >> SECTOR_SHIFT); +} + static void blk_atomic_writes_update_limits(struct request_queue *q) { struct queue_limits *limits = &q->limits; unsigned int max_hw_sectors = rounddown_pow_of_two(limits->max_hw_sectors); + unsigned int unit_limit = min(max_hw_sectors, + blk_queue_max_guaranteed_bio_sectors(limits, q)); limits->atomic_write_max_sectors = min(limits->atomic_write_hw_max_sectors, max_hw_sectors); limits->atomic_write_unit_min_sectors = - min(limits->atomic_write_hw_unit_min_sectors, max_hw_sectors); + min(limits->atomic_write_hw_unit_min_sectors, unit_limit); limits->atomic_write_unit_max_sectors = - min(limits->atomic_write_hw_unit_max_sectors, max_hw_sectors); + min(limits->atomic_write_hw_unit_max_sectors, unit_limit); } /** From patchwork Wed Jan 24 11:38:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528993 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 4814D2C69F; Wed, 24 Jan 2024 11:41:39 +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=1706096501; cv=fail; b=oh2vVMEmaiUOLD+BLVjy5kO0dy5XcH3304aNC2AEMwswjA1dNSx+86y38FuB2EdxAdEDXjztljsZSi9Po0p7cYkkpbUZgdpRdgGnr0NPI+8+qSLkwX4BZxDP4vXl3N24bqHfO/y44zmJJA2MV2Dq4BFGM7n+r3OusmvRxammYJY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096501; c=relaxed/simple; bh=rqg+aPem3Eu9+hiL3re8qTwC2/cIZIBrMFtbO7M02pk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=WM7eLr8IINLvHg6Jgekup/IOuYiHCAx6qwJxYVUuf6xSczSPnXQ9FtCO4uEs6D5VdFQJ+rCEzGEXY7gsc26bmNkUQv/ncRQtb9IACUuk84XE5vpSLaonUrf1qdVOm0VB6I2P/KzJv1irtHJXEa57bf5rnuXk5SwN4okCdRXqhNo= 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=J+00KHaf; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=hHITNpJM; 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="J+00KHaf"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="hHITNpJM" 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 40OAwi1f019751; Wed, 24 Jan 2024 11:39:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=hxFxtZezNioZYeMyVS4tuzmqgmdZtTTEjDURJOhcqD4=; b=J+00KHafVivsQou7nSNAoSTd+Ks2xB6WShAbfBoG9Y+Ghtyjb3F5T9ie/HHPQJPGqqkJ ulyAXaYBc6KbWu2BafnEV/LO7S4j3HokXpXYeT1DcQIJPPTptTP7PvhUcb5IfHIhzJ67 XyuLqGMOvybvo/Ph9zk4X3sUYDMfO5mAjWsTKZT08h+nx6njhYwAtXjBfFWvhqU1T73D /tvnyaXlYnEJrK0gcm2tSKTiOtt3DzUY5IXQ1F51DTvGI4VnqBUENSNyjrIB0GEJFrTv 5KMPmax6Z4ru2tFfyTjkgw+bl/EXCSD0mwIXg2NW6gTMzqJUt9egLU/R0Mrm9AO8n7w8 Aw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr79w260j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:15 +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 40OBSk74006248; Wed, 24 Jan 2024 11:39:14 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3vs32set4q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b7m70buIXS+Yd1m/0l/1ELni6nWwsNa6DlRngjF0P8u7TpevI83HH9FyekjNOpSpbROx9fmPCEGEX4eMCHvXYB+KTHcEQH/WY3MygnmMaLymyfY6nfuEEhLLZzqjqme9cm59JKuKlpyI3DluQvfjAgHTJVWO4Bq2Wb3x7WbkhIjzNOXCO78kvsewlhpmFXGRET/6MPWOm35kOpfd5/pWv/hwBpzPWj284R6XJeiKNdJYY/CU+WuhNcXcRJhT1pI6JHVtivOERQgGH/EvzLh29TUDZl6OoJk+KSr8R/APH6121WtxvS0n+LnXmh1dMe2TZDG/ceLG/qyaZLa7AsN5eA== 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=hxFxtZezNioZYeMyVS4tuzmqgmdZtTTEjDURJOhcqD4=; b=nkA+LFfIVwLD31eojrX4spXD2vlwTN0RsoSwrAn51ikROndXud+pyo5q0khoRdU7szy3H0BxHNjsnxtMTgp/scQbyNQa+YHfircvCvWlYrtT6T+j9cgax/aBRgekulkMMC9VFJqXS9eE7oqeZGncINv3CkVM7+gehNfrjomcm83EdJGq6tfINDtTWd2TO9BRuQZDimknpT8hFseMnacA3vLrjBnjr0nyRdEA9VNuALcSUU+Kr7414HLtgzYY773lyYlWEyCGlyXTam+5djSprbX+4k1GdjACk0OxUNam7MwYAIkVSfJV6P4/bs8tTJ7U7LxC+tO9eeiLJdkYZU9kIQ== 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=hxFxtZezNioZYeMyVS4tuzmqgmdZtTTEjDURJOhcqD4=; b=hHITNpJM9FwQZ7/b5ee7coNK7Mfn2W1KsORckwjX73PbooFA2gzf7/qdj78Ovb2yj9GAYXM+gdJq4SoZbg/pxBAv7VsLkTfD5KQoUEIP9aE3xFbdsDOaRMj6dyu5t1Su/9aZmOw4M6xVWaGUzZ6MqZWIKGmL0K8yvnHRffVRXik= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:11 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:11 +0000 From: John Garry To: axboe@kernel.dk, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, jejb@linux.ibm.com, martin.petersen@oracle.com, 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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, Prasad Singamsetty , John Garry Subject: [PATCH v3 03/15] fs/bdev: Add atomic write support info to statx Date: Wed, 24 Jan 2024 11:38:29 +0000 Message-Id: <20240124113841.31824-4-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0161.namprd13.prod.outlook.com (2603:10b6:208:2bd::16) 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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 03887da6-ada7-4013-6c4b-08dc1cd1159f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zBQ0264e0zKZJ1JDdcAYAY+ve6cQFzOREKebZWxp9y+mxM9H6jYF75L83bAS21/Pb6ajj2S0n0rhCv/cutsO2Etc71jwMvw3CwrWYv/Sapr9U1UvlQllOKdNEijVKjmAOlgMZLdVuPQVCwbbYEPLMmUs7q+TROmrt8wgNj3mI4irHkvVlfgTyn7t4AlbtoZ9HgpuDQ421/ufokoam3stWxvcg3htbPof/OBvinxxq+SGrmjiIvcezFywar+6Sr9ul7nkXMnRXUWHufEjfnevg08UAYyXpsRI2yCyvgp7SykvaSNCOF2bf9HWDUkiROUJngIHf/hpX7RaL/KzVG4lB/0lEDK4UQPj4fI5mD284z1ubgiIm2c+8hf6mxjA8H4FNXoG9CXGd6L97ZlOTpq/aiHqwf01CL+qIj/LCFArdFxIb/5aKGYiKL6X3pIiPJFtJ2/sZziRons7U5l8bk/vfHEKSiYC8BKcFisf0/AJ5W5AwdrjrFXck70OTxXaHlAQr+9+ZtxE2qQNfJf+3COqRBdas/EoM5Zmgv0UTqdODqTPPa1Fj8hGIOWPHPClxGF+qVxmW1WlbGhwZStoGLy8c9u1El2dPDblkeaMqO4BK+4= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(54906003)(66476007)(921011)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: C9hLoQORauqHDYE4O674akPz+LqNguh9K7l8nFnB/VojUGKa95bsoqJ6Xuy0jyg4PZwHn0DU0ocr8amV3DL+qy6DyWIhc7SlGQMG17TurYWSiv6b/c8Ds20cl5gJtxLTm2czcWBtKOXETchg0UYwBWy4WlhrYhmjW4+GlXqgk3KGnJDojkZeBAiC8T6HdlKmi58ruCGHwo3MMNLvWbv3T+CmIntfPkzsaRiYQDWQS2cx8SXjHOZEX++wDzyqQOqP7jceGh2/wFYWGUCRKuifFkoDO5MOXPZQAMLc7Q76s5m11YWKmd2wYnctr7/bFfvM/P5YjIKgYslB9ij37tcmIlFi+wx2kbUQylUMiDsrcrAK6xg2hwRCItCTyweWERmHXIgAtCOoAWL6L3jH+QsxnIUwDrYOSvDpxSdFpBvuP2Rm/73JBbSXHgSsYcD6k9sv0Cv908xtP4Z8dPnZecVwpupEUSHAhb0UwsEfcdwo4jZRy+im2ZXipm5uY5ExFJPJurUpoig/a+HoOqVjzD17h1xrZ7bBEtIpxAAgS0cBzHXBC4MbyC2N87AXc3Azmn3eShB7ZRiOdqv4wIIb/UsU9m3PhBgw4iff9FZQPmunLwJfZCzhaVo0Ugo6EcATy7BWs+cKjVOWM3ojyYx0gkqBCuLhP08gcE1e0uvXYlfUd1kDgqulb3b7Mu5hh28B2w63Wn1vPI+JOeKkfWM9v6x4u+VMl3eyFWsrsvyVUsF/V4jDV+wtIToPxMaAtE7QPHjVrbCGwP2UpHbZjgOar9qqGSbiqVwJVTKgO+/zsf7Cgxox+4uu7SHKZknTnLbNB8mzzMFSCpMnbcK5O4cmeaL76TZwsPCJFauhyFap73SDZfyjNBYi06NwUEbuADh/Sm/qeZDjlInwatWinFoeIGkkmrOeRP0SpQN2ACEkY6C2VGzTVzqOPE4Ir2iZ4Nvyx+zG4hfo/yw5/UsmgeFNr6Me3SWcBsxxviMCODtLO3s7HV44QFJC0FAh8sW8Wt6rJrCEB15Ok0IxHOmIV5HbecFBAnicv6CZRGn88TqjUEb16D1nzQih1/KUZTvZWbrjnO0Rt+QCVJQdsAnUUVNE9YoYdsPQOIF7SgpNRPNyIMGkC4t3RCqquV+7JaifZjWo+VqMKKzW97vMNH0HdCefhhOwMQS2ZEOqnYnih+Yo3aqVWcQsioqoiHkk3MJihvFrgCi5U5MtSOyFkn0vOK+6QRCmhJpB1gutVnx3NFYNrHqZBISCd1ezYN8tqkXH2FVEFEvmmNRnooOQp3AoYBisF5nRwPu+QoBa05glYzYXXWgJJv1iEcx8jBlEsYBLBRbH4SYslNmER75LOSMtEu/eVFXUFdADAP8rKacWSH2ROikLsScZ9/TLaRgvlGeMvmBGFVLWWjHNTcMoMkWGJYqHFJYKb12K/SYiezCsPRnUjlLFI0ME66dEIjotAbBwtPUOnPRNNO09KBz/HLHzgfMwg/PwwFx5JiUalX2gCJ2i39oUItUv4PCqLcr0W9ok72jhVJ4VjJtzsZ8hVpFnUbu6K17xAggRK2n1ZsBGqUiRvUmydPI6KTajaerZa4jF6YqYzcaYCSkNbLyrH2UL4Cj/W6HeDw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: c7QXgCUY355+g+tCff30S0kFNEpaOKwg572aDIikEXC/KdgSC+rdSrSgJlq6dBjQpX6PblBg3iJZKdO9YsNS89TXzea+THf3p9ygyRbBqQNgO20sR0S6cr0KdN9g2lrfan80/c1SMq5DUMRGtEYhs39utd+fAJA+JDVz5QHTOfRDqQbwsU3y6Xwx8qdDhr0tClKkcGb5n5XOR2R/r9wxfm9lj4/X77TmqEdEcOfuf5RcwUe4stg0ZkFzThg3LOnUutOBE0hZLD06UYvO0aE8Yr4sAi/hTvO7S4xbnNE6hIISJ9R08YzijgsKwJtAKytvxOLbLtT2etPKEtzRpTJ4bC4Ln57NfInsnsmWHJuqNigTs2aYp6S2ZGjWfdOLgm2nvfnsEd2XdASaj8kTSRrU8Cnk5TWrppiewbIUEiLojBH+Uf9EuM4Sc76pQE1T84bjK9F4+WXeadblk0TIKnknBN3c3rqp1s2MgN0jQWPSEXFMfJXCfR+Di09yhUIi2jczb2+T6M3u4KNS7DeERznmsclnWTvdBHWlkbMI7FNPYjAB1U90XErvLCBFOEEXyzuBszgFRsjNS6o0VXw+oWZ30VRTWnhhsWmC6OrzkkqDXIw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03887da6-ada7-4013-6c4b-08dc1cd1159f X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:11.7150 (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: 2GG6I+kCxKI62zpam9B2vNOLGF1kusZSTMitIT7k/IS3glQQ8CYusRG4I3j71aBbNbP2tRNAus0DraXWRq4JJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: REcnc5q1sY2IWKGKkUsDqEZQQ0Su3r8t X-Proofpoint-ORIG-GUID: REcnc5q1sY2IWKGKkUsDqEZQQ0Su3r8t 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 | 37 +++++++++++++++++++++--------- fs/stat.c | 47 +++++++++++++++++++++++++++++++++------ include/linux/blkdev.h | 5 +++-- include/linux/fs.h | 3 +++ include/linux/stat.h | 3 +++ include/uapi/linux/stat.h | 9 +++++++- 6 files changed, 84 insertions(+), 20 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index e9f1b12bd75c..2185084ffc89 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1116,24 +1116,41 @@ void sync_bdevs(bool wait) iput(old_inode); } +#define BDEV_STATX_SUPPORTED_MASK (STATX_DIOALIGN | STATX_WRITE_ATOMIC) + /* - * 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 dentry *dentry, struct kstat *stat, u32 request_mask) { struct block_device *bdev; - bdev = blkdev_get_no_open(inode->i_rdev); + if (!(request_mask & BDEV_STATX_SUPPORTED_MASK)) + return; + + /* + * Note that d_backing_inode() returns 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(d_backing_inode(dentry)->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) { + 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 77cdc69eb422..bd0618477702 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 the atomic writes statx attributes + * @stat: Where to fill in the attribute flags + * @unit_min: Minimum supported atomic write length + * @unit_max: Maximum supported atomic write length + * + * 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(generic_fill_statx_atomic_writes); + /** * vfs_getattr_nosec - getattr without security checks * @path: file to get attributes from @@ -259,13 +290,12 @@ 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 + */ + if (S_ISBLK(d_backing_inode(path.dentry)->i_mode)) + bdev_statx(path.dentry, stat, request_mask); path_put(&path); if (retry_estale(error, lookup_flags)) { @@ -658,6 +688,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/blkdev.h b/include/linux/blkdev.h index d5490b988918..443f08239308 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1541,7 +1541,7 @@ 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 dentry *dentry, struct kstat *stat, u32 request_mask); void printk_all_partitions(void); int __init early_lookup_bdev(const char *pathname, dev_t *dev); #else @@ -1559,7 +1559,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 dentry *dentry, struct kstat *stat, + u32 request_mask) { } static inline void printk_all_partitions(void) diff --git a/include/linux/fs.h b/include/linux/fs.h index ed5966a70495..c316c0a92fff 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3164,6 +3164,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..c0e8e10d1de6 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; + __u32 stx_atomic_write_unit_max; + __u32 stx_atomic_write_segments_max; + __u32 __spare1; + /* 0xb0 */ + __u64 __spare3[10]; /* Spare space for future expansion */ /* 0x100 */ }; @@ -155,6 +160,7 @@ struct statx { #define STATX_MNT_ID 0x00001000U /* Got stx_mnt_id */ #define STATX_DIOALIGN 0x00002000U /* Want/got direct I/O alignment info */ #define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */ +#define STATX_WRITE_ATOMIC 0x00008000U /* Want/got atomic_write_* fields */ #define STATX__RESERVED 0x80000000U /* Reserved for future struct statx expansion */ @@ -190,6 +196,7 @@ struct statx { #define STATX_ATTR_MOUNT_ROOT 0x00002000 /* Root of a mount */ #define STATX_ATTR_VERITY 0x00100000 /* [I] Verity protected file */ #define STATX_ATTR_DAX 0x00200000 /* File is currently in DAX state */ +#define STATX_ATTR_WRITE_ATOMIC 0x00400000 /* File supports atomic write operations */ #endif /* _UAPI_LINUX_STAT_H */ From patchwork Wed Jan 24 11:38:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528984 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 D3602481A8; Wed, 24 Jan 2024 11:39:39 +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=1706096381; cv=fail; b=QqWOkD5KXS4eP7+GslE7/1gr/D8D8Gavs2oZlJbOkc4jZX+5tby8TvdELSyVtg7K3rJkLy+qQ1ENwDJsU4wg5PaWs8yPIdkp2OpIFb1PvYuGzoUT7Da6xhV3cgQvgUdJ8kP2ICmzivMihinW+wg7MXoGIL/s043qebuXNgyUl8Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096381; c=relaxed/simple; bh=PMHDyZNfV2DC1qGD/isnS4zuBg5+k+pQEE0G8qmELok=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=XOnNJz/MT6nHFOgp9v84ZMWNq1E+cYAMqAE57uHP9TNEHbuiNPytKSTAX3t8MtJrDWzaoQf+KfIiCLpo6vSln02D1jB/5VYQ67lzIE4DYB1r4zEeZMKNl61E1ifgRU+a9hpv+cIe20PR1sBnWDlnVFoRRokdV0xAjlzWYUn4rVs= 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=bn+yrOO5; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=Fv5TJYGL; 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="bn+yrOO5"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="Fv5TJYGL" 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 40OAxSLc019677; Wed, 24 Jan 2024 11:39:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=Y3ME8YWCmtMyUFFF+UFtbiXw6J8VGJXY+lK9KpwRI2g=; b=bn+yrOO5GtUoQo/iuyGJafKFXm8dqvtsEuLAUBI1pbslBZ7l33IZrHXgo4AMvC/eyXnH Hvs1ituE2wJtitbQNRdpl8m8eIfjhoIQjlCVeMCJVPxhkmsjmKA/59SJjfK9gL4lnKv7 ygwY7M2H8CZko2YFKup0V4A4pn6aT+2F+rV1i+P1NUoySHqr0WPIN0Dy40/GcmlwPPXn B3iw90CaK/HqORyW0TdOaXV9WwDfROmOlEun99SrZlbo/p3hcj01KOxzpKUBZ2OpH+4v ZpUDwFW3ByNHFPog+WD5nAOQ1GR/vBN1PmtAuFy/5I/Auo/y/uE71AOrh31+JqsV1n0A Xw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7ansx8b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:16 +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 40OBSk75006248; Wed, 24 Jan 2024 11:39:15 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3vs32set4q-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kRbsPSP+8gLOp365nof8cX0ZgLhkC9yDiE364I2pS7XtJK6FzyKL7MXib9n67CeHGMjGjvfH1SuI5Mq4baF+yLMW6uqLLYUwb40dGBtGowMTIccuy/+935QgjGHzoHynMZupypbl0jpqW+28zgOUPnSSIhxUGU0cxo6kV2s8vwwioaRqYrEgwnshAN9PlqIRC8I57OzeDyjMLwUT3bzHWs2ZeMtlJ9aDAs/XKtbhJl3ndTFIsCsCkLUxtYPiHR+ABE5tNpNYV4K9JHPBvgfCM2MyXLZu1NeoyueR4TXMV0J6tvbxTEK55wp8rlULtJmt6INdLH0eExafUVpF6hzgjw== 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=Y3ME8YWCmtMyUFFF+UFtbiXw6J8VGJXY+lK9KpwRI2g=; b=VYHB5y5E236SjY03srFwu8OImKi8unpG4ZLkcnX+g8JSdpz0vEJb4000P244BYs1Wx3l+vKEH3r8KPI0atS2XOEjU3xsp1NMg6BAenIZ0Bu04UdNBwPMzoc+DikgSRL99l307ZNS5lNlxqzIaMxYX+QVG3Wpa62462jFRVRcMGIY9covr6ZRUmhL2PdO63Uop031Si0tHUI09fR0ovMIHVw5Lqwn3MQrCS4CU8MPLztNt8bqA2FH/PDHUBi6IwTxezQod0CLTwJ/diwSMtFfyujE/P4Z8cg6boAY1WKe98cob333TUABy3g8liJ0jBm+p2cBNvTlAAiTKESoYgTMuw== 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=Y3ME8YWCmtMyUFFF+UFtbiXw6J8VGJXY+lK9KpwRI2g=; b=Fv5TJYGL+FN7k5u+j+Sy6e5UyGMgrT/mMO+oIWCvaN206uEmKclK2zp9zaHgroOrF6EYfeX+VejV4Cv5ru8OOyIOhwn3oN1k2IM5sknlaOnIQA2a8qvIMc9qXCQHD9x9jc92dbeX0YhdrAmfJeFRF6gbF0ry7ekgveodOOX5nc4= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:12 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:12 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, Prasad Singamsetty , John Garry Subject: [PATCH v3 04/15] fs: Add RWF_ATOMIC and IOCB_ATOMIC flags for atomic write support Date: Wed, 24 Jan 2024 11:38:30 +0000 Message-Id: <20240124113841.31824-5-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0149.namprd03.prod.outlook.com (2603:10b6:208:32e::34) 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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 113ee82d-97a8-47fe-95d3-08dc1cd1163f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WVSlhu5Nog4/jD9oJqe296zNBOSYd5fvbEMlRdQLcYpvlRgCnq36Au1O0i1ns1C+meK9PcKG7sMwy1rZYgSorc3T0AhiuZqLtVNKL4U0JfIJV2AyVFKfq+DjFAZ4sHQTfz26Dk4ypGTlgue0Pxn7dsi2cumir51nXSqnoJ14IwZc28AdH3xepVlxbtwC+QqpEBoYKq/D4QO2eb06De4unCXY+z94DP0ElU0ta1O9JJr0QL3E9xsinETwDox4D5YS+V2k9PzYBTF+dEWV5KuCZ8CFhyVgML6XDeCjzVBLVyLoSFRm0Enjb94d4nutFvBJpsqkuP4ylUV6Bk/uJvVsTV6bQ24dk/YlhQKEKg6XeoITowAtIDSqENjJXzmlCKc12YTb0CuE6BTarBit9myGezJDtQp2f9PsWAARGV3k0AWh3hW0nOtHQkjak4lIbpJUsLCC0rBBSaKf3Nc4uhv0MDMcZZ0WSc0EG7Xbnt0FcdhibS9grv0mDuk2PM8tYiT8aAb2qfXIZLXcuP1vgwwNB64oZT4GnQ5TQv4uzkO+wQx5xEPTeqAul+2Wp0peDvvtz4+KOk1WHDbnZSD924bvrpslGWsVJpX3RHD20k8l/SY= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(54906003)(66476007)(921011)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hWWa66XePd8EqrJc8x8m5bDzrL5j1YL41Mjg7hxQws9+TK5F+/H3mSRwMszwyjGK74lOM8dEwbztk54O0GXY+cK/RJqUSNaUNB7/wZazEpQRWja+bc/9nC7tNDM2pNiUk3Dev1sHAQP4UwKlZrLkBTCHQCpoFAV5pGZGzgpg4sBXTqfglR+FvfBKTHhd2dEtfMm+XldPi0ZazMxB7wTt5wS/Ez5Bvet1lDzjWauvLr3VgWTwzKykkzRkCYsXAJ8UTDN2b1lhpSttuvrP4ANVCWm5rXWamWYqs1v6485UOY8hkOk6jGcEWUYeK7+wTDKz1U8v/3DgSAe/u4rkqEajBS9wWhXZ0va8aL/8oemeonzt7x9oW229Ir73KKW2TUzfCiXny9qrn8wyCk+x6nMwH9TRcZ4ihLPT9AHnH49DWk8183hpi380hOpyuOrFwQ+7iW1NASLDcPUdFKex/vxOKdWywHAVtFq00KGi3ftAdd99srs6NRCAkgFx+dWQWP7fdahfM5feiKL9gDO81p2yzgEJOWwghrkvRasanAtehVL8zae50WOPCee+4OdmdztTFvwle38K0xflbcvIdjYgsGn0tCxdXPpIeao9JsnNW/PPFZIGwPArPu5Uux0Rf2cO42HbPbx89Ksil1fcSKnz9Ts4xORs1xsBQru4wNPE9ynGoIPbW0VeGjuuhwdCgLQ0LRT+1iV1PqPLt6KtgPp1MnpXJO3dmw0O1zjaLbJA1p9K7QU43kyLXI4Uv30GZWEMd7XwPRUoSuOTlDLtpHcVmhBR93kJqXYskcRwpb1SNTWJ6OnjsbcQZkNeiaFHsUHCOrCwersA5v2ftuoHM0sy+gO/kByvPRUlyKcE9EUUQpQyGXGiokvYU7MRnGWwjo5bjAvPLQDNwgJe1PB9SedPbtrktLI/tST4nHUAMEX/d15x8t2UjPpkuezy97txFj7ltRLAO7qFPZZj8lv+NOnLQSv/ngLfvA9qqdyjQyRJYXA/Ac0dJYNwAayMjdsMweWlTHTlK1lfmI8j/qx8398806I4AIkgAsiVrmF63z4iOJlMLAFDRilRicQDjFSfyO3vdQ0PWvLRmOKzXvgf75TE3XWNxLk9Dm7Q1H8K7GVtXJMoT5IIVdYteHfvxDYTJI6Gn/YRRxZzoblUTh+vAioKABo1ROBwfjmYAjdE3dFrfGIjd+nk7SDR19hy+AALd0tixGhS2F7hQ2tldtLXCzd4S7vZatHVw+bYTkAKXVPNCT5So/UFo2p79EfKvYcTSbLapDiifx8wKQLmV1uqxIqjLgTU9IZXvMeONE5wpoEWUOnlYSDYZn/Lo6SbgQd+56WR749no0ms+e54HT6UaNn3HVGYFph4K2ZVTQqhVeSBUFmhkziJO0cPfMG8AKr6culTGgEhgjQV+H+3SrWaeM/i4DxMuolf0/RY+YIPswSrKyCqECS5vXoTwcpDRTlvMwhRzBa1qw7cVF04XbB0OZXbK+z3TZqxdtmBNE7NtBhXqAYM3nxLf5LgJ8hjmdzSEWVnvwJz2K5Nhii+IygCtG8qcW8W/dut2AEHl6oUL9eJsChAweexGkk2aBznqF5OTUFOfmXFfYDboQYebF3ZwwQTkA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: WuPJrjtTXjptXE5JAMYGLO1wOg5UGf2INn1/VXpwKBRJdbZ9vcJqeOXLReoV3JnRRE0IiZ3oIDfjZRND3dIxG4eMbAqWWzvJGAP2II9qqGJg2r37w8jaIEymfrsujOCr1HgNXZmZ98880w3U/whNDjmbnOj3/MyJK69rYnx+1edgIIuLiJXjDP/yL3ftd8eVJa5kRPSKI98sRu9EEKu6YjN93KsIzSMN8Qq/Z0cXT5/G8VPGLXBinjnrlGjfLBZlcZxSIakvKcmmHaN3U/AYzCzCtOnMiZCck3eAdKEcBd1BfRyaxAhExZCayOpsMsB8DIyPkispojDBcnfgnZpAH3ItoqFPJ19wMuvCEPmqgrHzOExwOcex0aQcmW/ONljWimb4IZHLEz6OAX/MUGLlc6g1uYEjIaDN+ZZmdDzXmMbY6zRbYLKRvg45c1p56hUL+NIxX3QeUfE+5EnpjZ6Rn2vuMDaeAfDQMHa1iislQk2Bn4q2EE+/R3CA/0XuhS9mLSAkzFXZecWv2Le0jIEJaQVLfX0Am+T7n0bQg0C8UNbwI2jT4TnodtlRO1uO/2Lk8ZY7IgDU0gAiRbpsCxEwogFY7L8kl1jHAz8k6AAVdDo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 113ee82d-97a8-47fe-95d3-08dc1cd1163f X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:12.8070 (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: QFZD4psspw8iEZQcmhZ9eEp8wBEizSzeJQFTsNedjIHOnRPOyX/KtACYv94NyhyGZfnnhFnM88rHIvR9k6jU9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: EaT4RV5_cPT46i15wjFhBWg7xJngzrci X-Proofpoint-ORIG-GUID: EaT4RV5_cPT46i15wjFhBWg7xJngzrci From: Prasad Singamsetty 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. Torn write prevention means that for a power or any other HW failure, all or none of the data will be committed to storage, but never a mix of old and new. 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: - atomic_write_unit_min - atomic_write_unit_max Both values are 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. 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. Signed-off-by: Prasad Singamsetty Signed-off-by: John Garry --- include/linux/fs.h | 9 +++++++++ include/uapi/linux/fs.h | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index c316c0a92fff..95a7e2889d2c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -119,6 +119,10 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, #define FMODE_PWRITE ((__force fmode_t)0x10) /* File is opened for execution with sys_execve / sys_uselib */ #define FMODE_EXEC ((__force fmode_t)0x20) + +/* File supports atomic writes */ +#define FMODE_CAN_ATOMIC_WRITE ((__force fmode_t)0x40) + /* 32bit hashes as llseek() offset (for directories) */ #define FMODE_32BITHASH ((__force fmode_t)0x200) /* 64bit hashes as llseek() offset (for directories) */ @@ -328,6 +332,7 @@ enum rw_hint { #define IOCB_SYNC (__force int) RWF_SYNC #define IOCB_NOWAIT (__force int) RWF_NOWAIT #define IOCB_APPEND (__force int) RWF_APPEND +#define IOCB_ATOMIC (__force int) RWF_ATOMIC /* non-RWF related bits - start at 16 */ #define IOCB_EVENTFD (1 << 16) @@ -3344,6 +3349,10 @@ static inline int kiocb_set_rw_flags(struct kiocb *ki, rwf_t flags) return -EOPNOTSUPP; kiocb_flags |= IOCB_NOIO; } + if (flags & RWF_ATOMIC) { + 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; diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 48ad69f7722e..a0975ae81e64 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -301,9 +301,12 @@ typedef int __bitwise __kernel_rwf_t; /* per-IO O_APPEND */ #define RWF_APPEND ((__force __kernel_rwf_t)0x00000010) +/* Atomic Write */ +#define RWF_ATOMIC ((__force __kernel_rwf_t)0x00000040) + /* mask of flags supported by the kernel */ #define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ - RWF_APPEND) + RWF_APPEND | RWF_ATOMIC) /* Pagemap ioctl */ #define PAGEMAP_SCAN _IOWR('f', 16, struct pm_scan_arg) From patchwork Wed Jan 24 11:38:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528988 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 830C25101B; Wed, 24 Jan 2024 11:39:45 +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=1706096387; cv=fail; b=CUTU3pzttcyK+MJ3r/A+FaOw2Jee/Ao2DINv36CMFjoRro7OkFw0C6Tufvdu6qLYWE9xBVoidvzCubMgu0VEU/T5w2X8RHhQCKhTX7ci9jUtEBeAmtypD3C0UyEbMcUpFd1iUsDvDMgDV6SdjBPGjkWtI3jn8VGDVcmusX3C5j0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096387; c=relaxed/simple; bh=QfIhboe7x1cSnq7qtz+SSZun10xPRPYrDu27KIXSn1I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=lH5T6Jv+m5u5B0ftt3HeF+gW1KU3q/ru7Aq6HvY5LT9ggL+8eNSYwupQjuviEBr5E2yUc5U2mt4soN5lQHpIYkdc2rhGnclls0uTN9OHnf83KsEJq8rTxeEHXyj+9o/74HcGS8Sau666gykuH4tn2xHcHhrLOfok000vmFeGJuM= 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=k/WtarCr; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=uNL8BBn6; 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="k/WtarCr"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="uNL8BBn6" 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 40OAxSHE019705; Wed, 24 Jan 2024 11: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=zrHflAgnjCJ3UbOqx2iGBxb3ow3LN9p3DKYbo/b7M5c=; b=k/WtarCramFlCVUHAgUhK9Z5H/asz9PvsO6rrgBvkan0qRr1UaAgAZZvOys+FBGXv+wY mvAlVEAmIGExXh5vFlil86J2QkPo7ykwLAhZdSrfXc8lGAlZ4GJ2JltvdAtIfmh/5Y4W 5OJEEgUdteIGkOkwgBRe1Dl7+0S+yCbFuycANrcbjscbsSG3s89MiuCJAJCNMYfMuVOP TUjhjLfsfQMgQ8KtH8r2c4tAMzX44VwTfIZP4FRBfqtLDYoi/tpjkRXZGG5licqAr7r0 GK41RhaA+ssvqbUZOHedhSJMBmB2Ryf4Owucw65RCiyuceUt6ijVUUvDe0xqg9DiSTjP uQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7ansx8e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:17 +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 40OBSk76006248; Wed, 24 Jan 2024 11:39:15 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3vs32set4q-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kQJO4OjMLDBqhHEqWtRRBo6wetCECQ0wl0c0tyLeX3+b7yJUtftCaz5xXCJZRa8dC833VcUrcA+3Kqck+dF+h2wTcRr66+RWzbFsnq8OuNAXX1F+n2apneAijrvgeSZZXtoRDJ+yrCeBeiqhBHr3NLb7RIQ1ztX/78zp+JwdkQvwp9SBoq7rwLQsPfyL7l3nNkEIM7SJYzeSrD8GaXfF2ZowqL9LqtbgI3s6bH1XawIEbtJGoRJECDTSdFYzDvRDx9ws0+zCQ1jjk+Gk65ZnMWNqId9qK5YXMNHvqLhR9iCtA+tOan1qGQB28oEnR05p8KcIYyWqFNf8E0AILmvtbQ== 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=zrHflAgnjCJ3UbOqx2iGBxb3ow3LN9p3DKYbo/b7M5c=; b=GwEfz5OYd6gC6a2p9ZiFSshFt5V9ZIcMu4e79hUub+UttQpP/YVsrCWrU6IR/LEN8NqaX7lVdRanuyWBBeaAByFRXsQl7O6E9EA6t0GquIwoDjc4YZji1i6toa25SJhhH6sO56/+ef0naWmaZzAkJ3n17XXon9ssH5f51Y9ZrXXmuyEhBESnMpb+k7MVOULiBGshCf7d4BElsvrNgHLDCPUusppZlA8YcmjipuDrqDKk0oT0EY/VZFQ8LN7v8e/LB2tJZLyh1snWu3O9zjaf5ycxGMeRmpu9TU2qLlatcSKe71PgIizpqzqScXdHe7SO18FkkgPeQ/4bnBiF2ccwpw== 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=zrHflAgnjCJ3UbOqx2iGBxb3ow3LN9p3DKYbo/b7M5c=; b=uNL8BBn6JCPjo52yCzmL4sfym5qzzrkbXRIWduCyG73lAYelKjXf732jOqz6yEqe5P/eQh+a/Wkxg1Y/OlQW8B2gQVcEPK1IYqZv5ArEUeuZPFQKuv5UF1u9UKQ9A+bl3FpQ7Qlu0eTaKkm/O8Y03mNTMfFcWt/GbjJJYh84Gh4= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:14 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:14 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, Himanshu Madhani , John Garry Subject: [PATCH v3 05/15] block: Add REQ_ATOMIC flag Date: Wed, 24 Jan 2024 11:38:31 +0000 Message-Id: <20240124113841.31824-6-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0173.namprd13.prod.outlook.com (2603:10b6:208:2bd::28) 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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d578f05-0c8e-42f1-7571-08dc1cd11718 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f8ylSI7NTcdB+uKtRrd/+mFeQdS4pIF1d0naF/c/xjc2oJlVBwS2VzJLCdkaLlSzq+GC1jufKwVwe2BWaA83iJow+WN0tM0mwlqAUP4Zp38rB5XB379GNeMqWmzhBCTFfuHzw1MyUf9wa63M81QLGRElSY8s7hA+IFQSbXhHTH7mUp7EIN6q6kwuQ0gnYv7sN0iB1XxemDcxgTNq9GarkfyfMdKhatjZ+4zPekTuiF5pQ56mLLFjkIY/opFleHOIQDAHRyRdR8uDcOhArx3otrTcM1Fm9UlH1XceHPhHRc2mYgsEEZwdnRj2gTfaRmDzyFjucUqHm7/Y+SPcNt7NotuW/lfNr68gUcJdbxme4hZnEMvvfv3DCoT7ufP9fKjByH74fXYsD6VvCRLLW6Pez4smGn3z713UXc2WaPCBJtC7tjKsGus1mrOZLB7bfQpw0iHyIF0w4eLRiMx5fRj9CvfRiwZWEei0thTix1QmGu64Vb8gKqbAKuC7F8kZw6+wV1HFELiQsc2u41U1/VCM5R1/JUbjzVQKJJhafD4BUgyeeemGT6/Vg4ElGx8yBmeZNm7AchkTRI/lKRK3ez1yfT0NCTl6wstpJ0oPuqQKXrU= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(54906003)(66476007)(921011)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Kndn0X0xmRSskrXQ8GLNH7ZbUzxXIhfrCYN3jNg4Qle9rmrxFobU+VJfInYSovGSaTQpB/AImY2dhszAjfVdo25YxYBS37FR4HmqhBKhI/xLzxOGEfsl7iz+69hzptA/7PPaGDSfxq/G9e1IsU6e+0n4cdbLkLDAPbvfNgisHRU76Z7y2ccWiTZsnJ5QmkdcBqLP6xu7FQbd4VX9aTuslBFJD7MUZj2Wr9fpx3szjM400r4yxxbhPFNfAaEm/rqlYsLqls5WrwIhDJcpaKLDuk43HT47DBdfphCZL7jTOZtlGiExGhdUYSLdvKblhOVMKkVRkGOF7QIpsW75cVDaLVbaI43LSqYwFUaKoL6PrAWWBbbZzm/uNhgLk3HptmrfC3EP6k9GnDP5KAunASDw+/Il0UzAdIr1++B6bDYtuqIlEWqKfluSZrPRh7bJZ7k2YMoMH3E/V0InMiruysktMbNHgg9WYI5dPcEIuNevPQ1lfc2in72+fZV8iNsgS2WN4BKRpnJWIbDLhchXfuhctTJHdytVJog9poIhjcItZ70qTj5wtTLuvYTJUc1cMex1mMOfBVlpPhPe/Ee2OkDcoSL2qTddufB0/H2a6CT8z60WoNn0D0ZV3o9GXx84P7GJSBMjO8n3R66+jgPfnt5dOeCgTRqzSZc9TOu0oOEUz7ytCJ0ihQn9lBdGtI2/OS0fQbN+xUxTOBh4LwDEyiX6uDw/o6FbcJqUsW04TJqszdRz3IisMcKPJH1s/FJhkavS7x+yqtebpN/EvQ2iT1F/BGDjOMBLwLHShdWsMpmyB0epFCihuMdvcPh4HpTb+OLqNaqgPAU8xDJVsRRx1BASLWepQuR7PMYKoqyUE+QjjXv1u9sffaKAd27aeWI32JTWj/iR/n8jXPkOihn77YBfwrvopqnRCuAuNB8PAJlfgpkextCy6Uu1icXSulQHLZHdAcAIewDRA/2Jfm7bGYMRAUsXaCZguoAbk9I4RBPscIMXt95k9y10bvaWp+QZ9URqLU6XPTFFmIuBxY1Vwng2e4Z0lRryBRcJeGGzfTMrWmxRjTTSnPh7Tp3wzch6V1cVg+XNwWwwl5ZKbU4ytlGZ/7frhZTMla56qnqxBglIEPTp7It93mOZqCZYUCkKLVsq27HaCDCVNAJ2xk8GE2NxtFqVPmWJhhUx7Y0Asy1hpMV4JO86524ftUgHZ7FoSc0tLFRsE2L7Ca1AGQo9S945ZdqBOnPoJCSOvwhz2bIwUksqD6SYWNxZu9Nl5+D/ifb/lK9dIr6TwecRUUyvQ2VkI6nhPvOdwyTFIgRuPxZSqVIa43mGokHzz+Ia3Mz9JOAxRzlViVxSy2kKJXTbKcwg1Zsb6RCA7TzKhXyKVl8WyWGKrdGfjV7EVpS4XMrnkOXYvFbJIjyd8xActNRXmMmhqignHOKAp1tTVtCPwqzGsrIWQVLH058Cd0tZJawSy7To/fLgNplGJb987m2Za1e8oURsogqRZGN83NZZDp263gH82yN6et+KZ47Nc+iF04cKAe/ugsK/9tuXEkdn37y2ygo3iYgDFZrRF5DanaGranRsPR9tvvw9Hp2pxGQ+06HQ0Bc4rWgfiME4NlDA1ntIyQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: JBO7I/3utf67B+Klpe5GGA2FM9DTvCVyPUoG6bF4rttCODOaQjI2KvW3w537HcCHZLVbavWuBDERJnBV4Iv7ucIlDmWYKe2jdyhIJ1XqAyGa8wL5O3n21S7qsghl6IhjCsMgoT7wFziMCoU00eymhLIR7+wGwZOUqdV4YFutnTHpeZ2YTNJHKP3SIqP/l2aTi7YLPaRGDxfPLoF+Ba77a+I4i7XIJvObQkBkhObb/rIaQz3JpwpmTdIwXa+8FuDM+HCu6OYEEd6MjEXznadBziV3UF0LKe+cgg4HKcoqYbR8+WD3bp7HhSpxdO/nU20/Jg+PwwMq/hHc20cfnSnOqIuCfxm06hPWLCw0Im4tsLrsVqJ3BFMTSNPXGwPIthIivjlHKxXGGsHgzvOTfbtMGjuNqcgmlNdPB04d8bI8AhYhgJ20YyUPsoeykcFfJI56ljr8i0lnGT5KnZP9983Zwr67rrI4DtZRTK0R2f1PXkFhA2eosgn32NyhSKMx4VwCY1IAJUqRgsV/p1YPBWHqHEpdWoK79p+RHTgxmERlh8CNrgTRBu/Zr6qYOfufDCgRg9Y0Sv8MU8l2zdHsq7XPZkY7ACDkK0ISEDQdRuQiVb8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d578f05-0c8e-42f1-7571-08dc1cd11718 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:14.1789 (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: kR3vEeieakBI8BM+t/f+eU4+pV7Ykaf4ghnu885ML6pj84+4namsLHrphq6fRa2sdgjpU8yZDYxWkYUtbXzBVg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: Y7Ciy7Y9iD-vjjPBU6PKwJ-prDW2tbyT X-Proofpoint-ORIG-GUID: Y7Ciy7Y9iD-vjjPBU6PKwJ-prDW2tbyT From: Himanshu Madhani Add flag REQ_ATOMIC, meaning an atomic operation. This should only be used in conjunction with REQ_OP_WRITE. We will not add a special "request atomic write" operation, as to try to avoid maintenance effort for an operation which is almost the same as REQ_OP_WRITE. Signed-off-by: Himanshu Madhani Signed-off-by: John Garry --- include/linux/blk_types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index f288c94374b3..cd7cceb8565d 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -422,6 +422,7 @@ enum req_flag_bits { __REQ_DRV, /* for driver use */ __REQ_FS_PRIVATE, /* for file system (submitter) use */ + __REQ_ATOMIC, /* for atomic write operations */ /* * Command specific flags, keep last: */ @@ -448,6 +449,7 @@ enum req_flag_bits { #define REQ_RAHEAD (__force blk_opf_t)(1ULL << __REQ_RAHEAD) #define REQ_BACKGROUND (__force blk_opf_t)(1ULL << __REQ_BACKGROUND) #define REQ_NOWAIT (__force blk_opf_t)(1ULL << __REQ_NOWAIT) +#define REQ_ATOMIC (__force blk_opf_t)(1ULL << __REQ_ATOMIC) #define REQ_POLLED (__force blk_opf_t)(1ULL << __REQ_POLLED) #define REQ_ALLOC_CACHE (__force blk_opf_t)(1ULL << __REQ_ALLOC_CACHE) #define REQ_SWAP (__force blk_opf_t)(1ULL << __REQ_SWAP) From patchwork Wed Jan 24 11:38:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528985 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 4237B4F61D; Wed, 24 Jan 2024 11:39:41 +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=1706096383; cv=fail; b=SiGgE3FQaX5IsoGip6BsNDMLAOAJIixZbEdEcgLuV+Fu9OzPvz/qxDVyw7iW8EL1tTKs8rbF0aIsvE+rydkx816gVbUdxQKPtp5hl3rVt7dOwA4D5AnO88lv7LPk95XjUIbUjTfg6+yMnSeU4XpmhWc5g7pSTal6J5U6cVuWhYU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096383; c=relaxed/simple; bh=hfKDfWGQ7oC1avas1KHEKrtI9VaV8Vr2pyG4OWWFAuI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=e+m7egufV5jjU/u0N54M2Mueox9onHZWQDrZl5lIUc2bFiJwBqp0NqedBWHouRcaIA1BfOfrzCG0gyzKQVev6Kr/NV2QTKyt1GWHVFA1A2hapev4V4m0J7/OSVEY5C2wsvTneRAWJ2TZXixF6HvHmyijupCOUHbZn9sgARrgEm0= 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=Q6co/w3C; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=aCxoVDEc; 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="Q6co/w3C"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="aCxoVDEc" 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 40OAws8R009422; Wed, 24 Jan 2024 11:39:19 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=h2FSGXiK1XSt3ABLXU91mMGcMxp5pW+utLdk/RUQ6Hg=; b=Q6co/w3CxBm/jd/LLbwhSrcuwAV3hb/UWs8DsulL9XzEe1WWefJ+6LuSsfvdt1pk3/eZ vK+ARzX+isRnatdZ3Daoa9uykMDQBxTkBOi0TjpFAie59ClaBLZB9j+0N8FyPmPUYitZ QHLQvcrbeygIx4wmB/wDp/qPV5/sZGY6sWNi3urfmCtEA/NsPwEsLSaMzvn/MirCaCmr w46F5FAIRoFTf/M/kepBOQBuYMr2PY98zRRV5nJsBl5r3673y3ca/rOKFJm7jOchnZQt lmfa2Nn0Nc4PMGRoy0dWI+m6Jg2+di3GBgwSY1ZDdSm+xw33VRktKA0zt8Ap9pf6kfdg 9Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7cy1tw2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:18 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OBZPMc015042; Wed, 24 Jan 2024 11:39:17 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs33un2su-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UwPI4tneY3foXVxTxf4kK0mEy2um1szYa2xCY4UuxRtl1zZK82AvViH5sRaaoht4BQ6Q6zYe4WOWbk3TV12aa/fxvZ6OljtGCTTUqmG3eYHQfcILfdo6RQg41ug5GxzRedFDw91I4kz3idgw6Q6w3dddGbA8yl7fRf2Nk5afOXnfSxwKWXxpMJBCarkNjaNiU0OZBSP+hy+XeJLFhfmcK0nIhv7kjEn2M4AEymuDnipVLR/4Z8C7hd95BpKynumYiKOoah/CAUsNZlwe0TKHDh+vhhsV/qtSkq9K1tvlr7Z4lUeCnDUdE8Oz20UQOx5PNzL0QNei0d/Pu0nlgMzEUg== 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=h2FSGXiK1XSt3ABLXU91mMGcMxp5pW+utLdk/RUQ6Hg=; b=P47Hv2swv3OIDCAHxlTvajfrlXqqcT4GkuJQP44pEHKF5+NnUnnIJevvAWUct4srwJM/2n1JjtRfLSC3RSMCX4CcaRzpxRWnCESwaf4gh8x62xDec2sKhsmo0AzlXtgMt8tqFnR9E4A9+RSu3UhPmm3UzRbPJIWp4LQooXduS7Wx310cYDFk/5eHMbGewcMR8J06Org6uC7+EqgvRVi7Sg+IjIWUySKwcRsukONy9jTvLLqYkX2ASU/QM28zDMTCHK5IvEaCBWXS7K+oO3EPvd/SWP1PDOphYlSK6tJ2LtouXYBNr6qswIHRywrGlcSG3t43tNGi/MRJTiBKvCkGyQ== 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=h2FSGXiK1XSt3ABLXU91mMGcMxp5pW+utLdk/RUQ6Hg=; b=aCxoVDEcBrDMQvf7n4Zv57SBJMItLuCcVdh7B3jvKH8XESPwk0tvizD5qn3PJiwdxNp7hkWIYFW0kSPBLFNdDumQA7Cfjiboc/XvApiPEuZhPiL53BDFb29KljhPF9JujZU2BleoQ1icHwBt/VcREhEWoikUwh9XnOUA5pTHFDM= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:15 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:15 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 06/15] block: Pass blk_queue_get_max_sectors() a request pointer Date: Wed, 24 Jan 2024 11:38:32 +0000 Message-Id: <20240124113841.31824-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0157.namprd03.prod.outlook.com (2603:10b6:208:32f::27) 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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: a6caf9e5-7237-4b57-57cb-08dc1cd117a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VQWphHaf0LoKd1I8gqEfEW3i/xMgSwAL4WrUmFdbfZXFTzNbRlwiLYSVBBxFM+MKEbj1JnENbzwwqfEpClH+GrZ5VPJKY1Vu6MrtJM5GbvMT5X+3z2heq4LgVRf93iLffOqt9SV6uwCeFanJQFsvAWDbqKttuwyIWdzw6BGGctzjDDZBzG7wOg0KHdw3xkXnDpl4bRC6/difL9mFoMEF27NIXd6zyS/rdUzERtmkdMTcUM2hq8UaH7sB9fTAKxgh9vClBouzSorB60EbdneG4XR523tPfsVG45VPtSbiUhuQozZr+IqsBqyJXwpdN5wsAFX1GfKLKo8nCiC0Ordd8tmIzfoCEf6HNSc8KviylEemaV0nSjKqQdlImcglJOy5h829KvjTscf66/OuF5Xuxm9FfyUp11eioBMt1wCpvZo+J4d7a1VBNZ5qSmmh4+EkXmPhu2ef0eNCG3RSQ+12LjdZmDbEvaNALUhZwBUPL2Bt8xiXp2uexiasvQ4G9VyPYWjrZAdHl/yiTdXQCOKyWGyQPRnx8hbzuMW4C9Pho5Pu8R9Q/lwquYlN9mNPX1VMtCh78w1EGppZcsK07ik5vTKxcgcrm3cJrvZxxq0O6co= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(66476007)(921011)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F3cVd1AXadHer715j63ESNqI6Bs7k9wtBkBxC3I4QAUHuwtDODwzlbLnsawjWEhW9P3OKoCk2FVrLlsNAibyYPuCtiZMWL2+BLu0APLtRerNNv5f6MnRQpDpHyRWJZLcBv9qqYEG+An9IRUc3MQyzJuiBI93PywGnjtLU4p+A4Wow/TFB2YSdj3j+VQHYV/MzXnHQ7gif2T4aDQRUnb8hO5FC8ZhSXn3LHqEO6utq3ZH4WMwFn2711HNwfQzuMpeQJOgBFmQ8VAUf9U66gtvPFMRISaLNJXqHxJfyX2WBXCw5DX9TSAE35EWnuHWN7Y7ttJ3wuVKDIVnHHFUd0nt+aS80JAlE+cLR+2bdEAO0vV8gy1ImN/D9/M8KNy+KAfwROCE/jbLivhLnFEUgATvxZ+7uBZxD0qF5w8yB1BA/wfJiLnSZ5v8BkeaDm3DtORF1kD9kuUaZpoSwdNQ0xMceOLanikBeZQvWSWmOsSGX6J74n/yZiiAQqi+ZU2u6WyxpDDEVW1iETnVvtUobjsTVP49lczN7uHrUF0+jIMp1uIPAcukUfn0ThOnhu3dmqbmOBwyh4s9E2dit+Kiuusx35VtVXay6rDaqZCTpJdAfUhTbeglXQnoxptWJFDkI4OzIqnoOWTqR5L993wVIvt5RURptQdAPbPgqi5EN2xceirpb3XYVvU8eX3KKGpIHgmGS10PwplHFSGwQDijFhA5lpIhfhz0oh+gqataKL68rg8HOxeSB1Sr96VMJFpYW+5tDwX1EkcRt1B1UvMZQOBQaxkLjJvNiPj/dhWHumX0v9gqPmml6X7rmHWRu/DamBF6MhGRtK2qqxFx2aTGjot+RhHQY6EcVWIPNsJHc9ArCbQGZcX4Cz9Gx6gqWTpCnoT86/3qICa8iWck9KZiEtnYEmwL5dBBHe7xrs8OCt9SWgVm8NKV2+2slT6o9naRtdAiEVqjuKEPH+jTzcCaYvvJhA/1/dUJdUTfIyZVywuyc9S5Zgo/tCl/oeZLgX5Qq6wwUZ9E6FMe88XLgV3tI95aTcg/zYNMysem0+ZnVpRXbZk0QxYANqUAZBBmGDwDoiILkSN9jOh0AvDnMUI1ArP3YCVmzzjSsamAGPRjzpoYeGO4yuwx/0/zLMy9hRZNhLpM67um6Sg+qwuzKtxju5CBciioCEyhyfZiDTqN870/4fMMlJc9pnlws79Jtwk7R06nxuTFr9EjtHJdFq14rcuhJYfijUhqvtwpZnVRUVfkp+MW5FqmiQGfdke491lN6b+jlGtC+2InFHcoTnXD+R59Uxz99tarqQ/hc9iuG9M/Z2fDsno5hiMmYLY12wb+nT4waxbtMli3Ud+AU7UVPIIC6VCYPRZ88RQyqKt46YfdbJkZSb0MJnoWZGYjiKkzjqAiv5DvA3IjFSsIvTy4+Fyct9RJwpQ6ZczEW8nOexvIJL2xMwf5Qbi137GU6nZdcnAO0zlR+kJ3m+WdkaoA1GFDzk58ZDATiHgw8McKQSJPRwQHEU+VdkdovtdYl2JXkzMj7kc4Vw2M3RjG8dEUhVqe2LSAQULI4G1f4CiT8rUtnjMyA5dtIGCWZ0e/Upe7QPx+7Op6k0PwBHtL3cD+zoj/LA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /5gzOFoP3l2JYN9/ZAn7+czf32R2mUvSn3NSGKce2+J5nvfbZdEYVFEU0isAFDv1HWwdNLYSyKhGxz8Wpn26pVpdlTd5G4JfN5TkFQRIHZSRF/FapayeEt2Xej5xhvg9g5hgELKvKtOSZjR/HY8Gx+gJQZpSTayP6xgp61GYOlE04Bez7lpftDQHygE6GMO4Pg3Q+Jsp8v8SVGSH8RhMw/aa/E+OoFE62Of7PbCZPFZMOlw3DBg+BhIgPoF3ioEQmLvTF7orNLp9B7YdnDi7WJcYYcbs7LtfB7Qkx3XXTqVjvdnyEjKbIBXj948ukXQw5GNRaTkULEbqEw/xUWFAK+wTdoY0vnxOtMHofi1C+Iv+AwcQY4c5HhWIKKTi+yglQNdTMAtCz7nHQtLftRC6FKGA0vGjvz8hV0uG1G9EZiLEk2ZE8nuwS/9ay/JcQWoAwtIATbZDOIzQOugaEEgQmimw79dbvKCYfN5t3GY/ajeZtMKFhGQi+2Jce+949pb9uKUYb4PtrAOlcN2S4IM47uF02GNl+QecyDwa6c6yXCXPPziHnlRR+DRU5K6xewD9MlwBAn7DPzlGP3G2uNMAI83TAfrIcaTkS2bbVBGZvLU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6caf9e5-7237-4b57-57cb-08dc1cd117a2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:15.0788 (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: FNCTVkz9r70Fu6AeLIMe2dqNTqUarPgEPyVVMPabIs+o/NdyT1r2pgpqTNbWNg0pOXenwC8T6qc6l/Ewnwe9tA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-ORIG-GUID: XH3RTzd40sCm-b88R0rhnSkO0mj0DOze X-Proofpoint-GUID: XH3RTzd40sCm-b88R0rhnSkO0mj0DOze Currently blk_queue_get_max_sectors() is passed a enum req_op, which does not work for atomic writes. This is because an atomic write has a different max sectors values to a regular write, and we need the rq->cmd_flags to know that we have an atomic write, so pass the request pointer, which has all information available. Also use rq->cmd_flags instead of rq->bio->bi_opf when possible. Signed-off-by: John Garry Reviewed-by: Christoph Hellwig --- block/blk-merge.c | 3 ++- block/blk-mq.c | 2 +- block/blk.h | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 2d470cf2173e..74e9e775f13d 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -592,7 +592,8 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq, if (blk_rq_is_passthrough(rq)) return q->limits.max_hw_sectors; - max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); + max_sectors = blk_queue_get_max_sectors(rq); + if (!q->limits.chunk_sectors || req_op(rq) == REQ_OP_DISCARD || req_op(rq) == REQ_OP_SECURE_ERASE) diff --git a/block/blk-mq.c b/block/blk-mq.c index aa87fcfda1ec..78555e1a2897 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3056,7 +3056,7 @@ void blk_mq_submit_bio(struct bio *bio) blk_status_t blk_insert_cloned_request(struct request *rq) { struct request_queue *q = rq->q; - unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); + unsigned int max_sectors = blk_queue_get_max_sectors(rq); unsigned int max_segments = blk_rq_get_max_segments(rq); blk_status_t ret; diff --git a/block/blk.h b/block/blk.h index 1ef920f72e0f..050696131329 100644 --- a/block/blk.h +++ b/block/blk.h @@ -166,9 +166,11 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq) return queue_max_segments(rq->q); } -static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, - enum req_op op) +static inline unsigned int blk_queue_get_max_sectors(struct request *rq) { + struct request_queue *q = rq->q; + enum req_op op = req_op(rq); + if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) return min(q->limits.max_discard_sectors, UINT_MAX >> SECTOR_SHIFT); From patchwork Wed Jan 24 11:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528981 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 9C1762BAF6; Wed, 24 Jan 2024 11:39:36 +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=1706096378; cv=fail; b=fI/z0bdSlYcFGy+y2T5j9a9mGNKRNC7XKTivojqELmevtOz9ihysPjs/c4dzT9QwcZILNLqukHayeOK3ExV9gv8yyTIqrGWGZ3RX0sFXCGXDaIu0OFm+Wso/Ad9xWzXGqe5kT0z5w7i6IF1znXsLCthgxyutRf1sQwPUiO6GHL4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096378; c=relaxed/simple; bh=XNJfSX85fdmd2YsQQVatnuBVAzd7ZexIHNZEllkOQXI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ezf1wHWjaDp4YgX/TNTXsE3YkiaGC6hfZvN8agGLfcKqAuXx7qzMCEfQaxeS5HmlH3yYjZSDIOVxE2anqBGTXUHht7It3IZhs74697elsqha5MX9+v4oPVOV0ufY7ZZDY76g+Rpc0y+avgsLJLbi09XJtG+Re9Ov6rahTMGOZOQ= 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=S1LvDIWw; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=YwvK8uN8; 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="S1LvDIWw"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="YwvK8uN8" 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 40OAwsNs009429; Wed, 24 Jan 2024 11:39:19 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=Qh/T1MFYYUkLwR5mFFWEjx15hZf9sYn1Kr7j+s9Ho6A=; b=S1LvDIWwvA2vzQD24LnRqqWLZsb7+BZaULHiBTpCDP7oFOkdiG4BsCDZOns0jZcRXwB2 m814/mdSxy0ifqKxPPKrEsf3EvvH7//+mZNjQ2DQSG01BlvDEbSldaBZK/NFs8O8ctz4 OuIoUExPEIO9PgKUHkMy/F+rcpJMxr2Opn12GWL/XErD+Ldv9ZOhdGrSkR+TKXZ+ipLS x5qz0SBKRIBoHxZpYyCDwfxjmu18knk0LioX14brN56yM35nHvjJzERd/WjODVmQUjXA q2jmZCogNEHct1Sg6xYwT73ZARDqU+hp3VJLup8PJAnPePz0jrpSmvTRxqvYNeZkAKFF 9A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7cy1tw7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:19 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OBZPMd015042; Wed, 24 Jan 2024 11:39:18 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs33un2su-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MygGfNm1ILIyJCJyBjhinuT7SAJMsP/zOeOoNR5Y3eld8gfDhdwbbICYpH+FY8lzblNmjg3PeLsXnPE8/LIL7N3VFg1R645nU4gmlPCrMFdO7AwVCVHoCpD7osfhA/h5W1wvvwqXZejKYuhmNp4CUCiEu+FBIQEfJxYw+RvOPP3GJrS4LcTCVEZcfrR4t/VNELWW4bhpor0ntjWYSX3IGGzRZAk/UwPmL1B/dWQVVgitrsC+zyqW/0oeBQo6QbltTalzP3PNH/oSjAG2wNrHiCk7gm9TF4XwkhefJ4ya7JK8dn6wAYYhvVAA4e7GevhRIfIkjHtYvY8nsjprJo3zMw== 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=Qh/T1MFYYUkLwR5mFFWEjx15hZf9sYn1Kr7j+s9Ho6A=; b=kOTb+2ye+l9obkjhN20OQ0RG8UUqkIx01QfwbCF0o26+NatujmB2O/hutN5yWFIo2ErvS//rOmbf2B6DALWH+CPUnzjRvct+t+6XnG2Ikwfl/duzcrYv8b9PoHtlWVyhtp0dB7jzNbVwppyQ+GxYXfuRPPFVy7gFqbo4QG3VYX9/drbnvRI2StN3l3Z7Df8qtR9fLgtaLTAFd5meRl5Bmtx185bIiGGnZ6BU+Ad+cicvbNesl2cY551X/YHwXIsZmyK8/PkSwXCMst4Kqth6dehi7/V5ysNSAtsiEcfkqEvIhke7bV0JxG0I2wzx+MsVVJgfEgW6FAI3KFwaLaRecQ== 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=Qh/T1MFYYUkLwR5mFFWEjx15hZf9sYn1Kr7j+s9Ho6A=; b=YwvK8uN8VDeyKR6B673nHYdYiVX3NjPxrxe2RR0SsqPwssu1gl9IXVYFEx+R5Bry9/kqrdqy3ClG8A/0bWrFhNm+4QqopbAghfQIH8k3TeElO47DOfmwbr/pbogctN7zQMgd+qcCt/+ZO8My4HDDinuyMGTcBQ0QV5iBUTqIoW8= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:16 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:16 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 07/15] block: Limit atomic write IO size according to atomic_write_max_sectors Date: Wed, 24 Jan 2024 11:38:33 +0000 Message-Id: <20240124113841.31824-8-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR17CA0012.namprd17.prod.outlook.com (2603:10b6:208:15e::25) 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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ecb720a-414c-4eea-32d6-08dc1cd1185a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qBa+bjSqn6QL/TGg5n74e4TM4F/6QotEf4HPIBcMSW9Hdh7uKApTLo9xzgJevnB79QDoTMYNUlJD0tEqTYpK6ep1dx8EvHUMxP6VjCM3JZoVfsklRupBtNZkmX6HBA9fsqBu0jHfhID9rqCjWNDkpOzoTVFXwcALU6ny1XG4adre/IbvZj0APA43aR8Fc9AmSOj/jQa94vE65PrrcTEP0VHb7Df9czT49GPgiuTdwY6EoCD0DtR3aRbkrICyYSAIo6LRXO1mMZElTH138h/QtZ0PKenrfQJztcVlAdudqGlbvCjPkenxo54ifVz9XSHbova80XqUwFR2GoAdRkT1mBD+M2kDSEr2oD/n9+UrZzkKR1OaBZHCI1l3aGPXoAVPdoLJZSWZsHkqDcD1KljAjAK/5P67o5zbF/3RnoL0Sz9fvuhgaXUy0h/4ZmW/KWo1bdmVGBDiaTzd4YKaGON1HkHwDWqzXWHXlxJRAZIapAK62P5s1ZCm78WNaeMsoaaL8StrI8ww9Ne0p+hjV6KmPzHC7ON2NoIQ6P+DJKCYFlotvslZ2Wvlk1R+SZC2U+fZ+e4zBsArOYHmq5UnubN11mJR3ekoT4Ek5i3sG0zOQFg= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(66476007)(921011)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qBG4G761nKkuu250+h8+6YZKN0yOI4RhhO4t/qcnaQZaqyBQsUwfzJx2DJHdo6YHFxGDH0fWLfojYQY2cxPXaslXm13pTCj3Q1I3vdFYTeoA+lQ0EP4LTLiZSMuWj8c8nK/Rk9T3ZaEvrAgE7UMbABAM79LqhMI25D2WOxdK5ZA9jtFx7hWU0V6k3luh14gOfVr/cJ0QjWnIhtwqnOJED5iYn0x1P5CXpVAIHBZdsuUq+LEeAKw8DMAb2xipcdEhNiyDiOPdUYGihkzyTUHV9c3wOkLKB81slVjSgF4duYL70wZWRKHECd4hiP7qA/QM8uy+cTzUky2thUTMwB+51KPNF8ems6Q1pZv4fDn+UlV5QzFgvSgWHf51Jv/bPgrBP4AXnEYLAjzFbIEpy9ioQ0FAKiiEdGux6PCO+p8Fs160/ab63FmsOWBIO+M9hlu20VecXgiqgFaq/IoWBnx/SviUKZt1bXsjJuE0vysNrwmJZpgDixlw93JBju7NjDjKS9gmwUz5XMx9gQ1xANCHfMouOhcTTRIKf7Mab4JhXHp7wVnis0CeyPcxoca2KIQXmXsXUpcPlfJfQ/VLA9nCqVLjkgPI42qRptUdBbeeT6BouemZFrtbdCAfcOKRNHnUMLAtNtmn7lyg7dMocYqXAmJl/rV9sIXr4AIag5MSmVSfSvAqC2Zx17FV9ZVlr7rEzRaByfliA5ZSspLpJiFYZaW/r2JwLkPV3Mc7hYwpxNf0YwPEbLinWibHgeRXvWo2vZvq1A7EKw/Z1yHjl6LHgdH7FBPLPjil7EOh+KaAOn4dhG3752nzNRuC4wPBla/WCsTNUcyolESlm3V1lEFX5d0YK6wUrU9Hb3jyVtoxNNQU5lsdTzs2RLyUfW+av0fBA5k8VSh9lRZZcMRUoqNJLe8heVQzelVEl8KVNx74DrxRPqLWw9/vtx3es5yC1ud9MPb26ISMIqd/2yav/sKz480Pouxyhg2EI1DfhS/DIKhFGulX53ylxZK6ljX+2rqzZQHavb9dCwE51BpKr8fzPVfzdRerorMiMftSzmPLo+lplwgfwlt5X3zpxg9k7IrOk/BqYFJR1Z6xtDSvL259ewtI263OJPQSPtVBLwfjCYgGWPnBHn+djpCFXf8ViotTTBu7ukcm+6fG5J1dUX3ntNUgG+BjImd8Dmcky+YRk/OsSgSaonktH21EKvYLqmEA8gXk1SV11DwzUGF97oYCw0at07QksCVvRfyAV7yYRQxVRB14TiRr86k7HDex0gi7pubxlnLjSQIzqfFxEKgYZj4+0jNgJeBn5MOouC6+anYjKwXrSkj4vQE7M4lQY2xHw/oqOjJrJOkoSRNv80F0+OskqZRw1Z6ZziOvWdd5rZFF10fXlWMwXsDDWpVKQcz+VgBf+B2k5HbCWMTMpytoY9Fnsj55pNrYTn15036hBZ5Zb+NX0IRGRDZZLu1gSmtPrujidIq27XLxyCNIoCB5OmTFkRMmNt1Bdpc0zgHN/Ad8UI3RgOfNppYBUkqkaY329MvJFqMPp9nK30BU0M9L9nKjYD7h7kSXDytRJTPDKMkN7TuE9G0LwoZvYOqdkZ3hrkxxk3aO3yd6xZlQG8fiQw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /p3jgv6XJrzMroCzzl5I8OM9wBx0vDjPeCw972aLH28J5Dqmil0l1ncsN2v+M8J2JjtadzkDdky5VZYk75Qe8hHRIdcOd9yM6jxSEkHBT2gVnUfz+LQ2EpODtRoGfm7EyYFx9tW/geMP4MPRUBUhoMreRnMctPciyENph52NoBWj+Lrga0/vwi0cNDmt+JzQN+9EHpegP9jifrzd2od72T4DsTd7gFAd5eDw9/jNBqXL/dRLXR3WK3N6Si2HLmSIXVEyPnuV6YFp08bK3NA50by5fCHuwMW7iWA6iBn8w3JM1lDRJkjnu/kYJhkWNEUzMc1OPWO3ZZRncTNR5BLSN7NK1fkxYoY3xCRI9iw/0PRE83Y12WZzsPMYL7jrUfnWRgze4WwfZ4ie5SqEjEJrGUuQq5efaM9pe+8+ApW/wdPWL0sSd3f2m80cODYpjIPrDLb3f87i7mK6RCb1lRbtnIjxK7DszYC+SJVzBVf+dxsSJr2goym76+HTht0k6RVDM5AI2tq/dQa6C6WKeCwrBVrp+vuUN6Y6v6DOt6Go5WeZ0OFcMlbVXWNlNH3+0MHALctVFmCjpXtUA6OVioBT3f4C13LRvrRxDwC2+0Ai1rE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ecb720a-414c-4eea-32d6-08dc1cd1185a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:16.3109 (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: spDsIh70PpUyxLasiNJfzKwPNvTR48aygKz5jzZEPsk2pgJaKpfTShujl5um/Q0E2rshwlpsZ9/Kg02qsruhXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-ORIG-GUID: bGYZ67zP7H4c9MJFATq6ujeDp06I_uBu X-Proofpoint-GUID: bGYZ67zP7H4c9MJFATq6ujeDp06I_uBu Currently an IO size is limited to the request_queue limits max_sectors. Limit the size for an atomic write to queue limit atomic_write_max_sectors value. Signed-off-by: John Garry --- block/blk-merge.c | 11 ++++++++++- block/blk.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 74e9e775f13d..6306a2c82354 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -167,7 +167,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, diff --git a/block/blk.h b/block/blk.h index 050696131329..6ba8333fcf26 100644 --- a/block/blk.h +++ b/block/blk.h @@ -178,6 +178,9 @@ static inline unsigned int blk_queue_get_max_sectors(struct request *rq) if (unlikely(op == REQ_OP_WRITE_ZEROES)) return q->limits.max_write_zeroes_sectors; + if (rq->cmd_flags & REQ_ATOMIC) + return q->limits.atomic_write_max_sectors; + return q->limits.max_sectors; } From patchwork Wed Jan 24 11:38:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528986 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 5FBA64F8AA; Wed, 24 Jan 2024 11:39:43 +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=1706096385; cv=fail; b=HR2X6BvA834FVO4a+zbkcPDn/MHtXaJ9OBoiJCLGoSuVK3AnUDdNtXSEZJv8gs3qpbd+JotfQsrvWy81t7Ce3f0+GVBWU/MHBbIivqHPHK0pvOPtYyumfK3tnubxrbnYHTwqj9WvFluXJ40CrpHdTWpxVtKRCGwX3z24BXOX4UU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096385; c=relaxed/simple; bh=t+4MauSfpelr6E0smUJkdxQruWwFtHAGLpwiu/pkQdM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=CV2whMjntECYs2fentO9FfCYckDUrZGDeq/EOlfHGqJzP6I7gCvS0fpe0eQw0D/NjzWjubyjoo6LIdrwl5OUsWllJ5ErX8nrAopFaLVKrB9urTfTauNdFkkN5EGtfk/pMOHdI9WNMytnE/zF5XpuL9/Ma3vv8+Y2TfAKdirf3kI= 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=OfRuYyAv; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=ksWdp57P; 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="OfRuYyAv"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ksWdp57P" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40OAwjmf002360; Wed, 24 Jan 2024 11:39:20 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=1YTAJOF+4ePPmPXuGvY0i0t3F3h+6l3GyGG7ssfOAMk=; b=OfRuYyAvPbPIpYGe6+WDWnWmKCo41zmpd00y9IrUrvatj2bU2NI+K31Rhikpc378F4p4 tmfnGEm862B6/eVpFhAp1asmkz6+bjwCGSHbFa4rvtZ6id1G0s6MHGFzVTpN2lgT3vzs yCME/4dHOvzygaxeqh5GOzLBl+Bcd1cPLoaBjAOlKQKU6un7QJGwqoKWS2lPNFOklcnM vIPcoCMkHjI7xM+lPCMIG0/IXE8LuFwMU8ypO2G/ZvMhwkxzhvgE7UeJJoV5Wh5eoe4C a6iFARwvKeRrLtuIHPi95HexFJoUWi3ogrx1cidNEnXMRxDpXMNQJfQSAG/XubSg7gwa Ew== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7n82386-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:20 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OBZPMe015042; Wed, 24 Jan 2024 11:39:18 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs33un2su-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BImEE+KydubLouKDHY5lgTl9DNAoSZv5rbPWN1cZZ/HPpNkdPRLZVBzEzhCtJAkz8D8Cdv0gIp/WJvXvHQJiOyZVxvTztr5T+7WRPultbYKAMskytZIDUytWhlmpYE//A5phMXa0WHASaWgxJ1p9zLg3rRvYaK0mp/RVsyxnrPjlPqvVcmCa1gi4ov94BrERlfGzlxRMVssJuU2+mdWXKJaEsWeQZeHkRuOwPuyx53nfK33eJ9HEr5PgiqR/C9wUFxLJw/xTgMDSwL5PMf9S19mBUtF9DyeTRdHXj213nbQXpJVUsmRKokJwcO6brnc7MyFEoqOMQtpNJhd0GSMKXg== 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=1YTAJOF+4ePPmPXuGvY0i0t3F3h+6l3GyGG7ssfOAMk=; b=bFKG6ZkDyeRF9tI5RO2O+wlvhxAThzlcT5Ej5F7PVRODK9tnTyfbsEiz2w9EL4w5HCYBwSMDxtnXZRqBiAMcxflIgZmykC5I5CNziSb8RZg9fwacxUUKYz872LLI3wrD1H7ny/oqMK831khvPEfVK9KM340g0qtUuyXz6Vb6hXBcHuaUnAOZzsoyvY/jg6h/D1XmfY74zLRQ5ixoV9Tk8IiF5DEXJYpz0j/DcNWDxLU8WD36lkxmtmZ1OAhoo+bpwxM5Vl6dbGYGJaGi0j2LYDexLDSEJDIpCBydBnjvIqyVT0ryOGH/Z6774+fdUBZvPM/AP5uDSXE3SBNHf8tRvA== 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=1YTAJOF+4ePPmPXuGvY0i0t3F3h+6l3GyGG7ssfOAMk=; b=ksWdp57P1mIQFvEcc1ko2L+WCvfW93ZFjQj/XJbGb6pStIlAX/b5RPgC/JjOyifeYTVKZIR/3IsdIX5L7+cUSOZLgcVN2XOAfqwUs4hzbbmCjw0+GEexx0tOscVY43YH+rMLyFOD7IsRw3UdBpuujvxq/9tFoE6+OtRHWQ8exDk= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by SA3PR10MB7041.namprd10.prod.outlook.com (2603:10b6:806:320::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:17 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11: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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 08/15] block: Error an attempt to split an atomic write bio Date: Wed, 24 Jan 2024 11:38:34 +0000 Message-Id: <20240124113841.31824-9-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0179.namprd03.prod.outlook.com (2603:10b6:208:32f::33) 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_|SA3PR10MB7041:EE_ X-MS-Office365-Filtering-Correlation-Id: 8414207c-901f-451a-e7eb-08dc1cd118f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i82BXslXlNYB8IZXRp4Oa+Cvot8bCEvNOmBFuema4M9FNcoWpCK+kV+J/kt9k0vcmbOc5B5YncBSh08K7IrAb4e4/pfX+lz6dIYvt2u4SaTjQJYDdzQ9Zp2Tdzhi5Y/cBuStMgYKHTn3bJ5fij1B7eKsvG8rES7IAHzj2PDviMMGwWT+lte09gr/DSL5bmPcmGBDusq3hI76httjADWaQVGTVgmPG1RVUNEUc3a4UgwIpVR8na9Y7YHOmtQhMJz39F5miDZ4pS899n1NNZvrVnocZ/Mk2hMKqQCVnSR25/EMQmuILrBvpW3AFwIHf8BUkdIeVTztQmRax14qXQREsCXCqcCPBWoIWpFdt2GXcv0a//wobLwBHlgliEGcXaNK/TZfyaHuxVFnsqpfGD6zOF1chb+DmtDSjrY4Gma244+tlFpU8tpzAgxXWGyuggsv0Ncj0fqmyqrIuZXe3qPtvglCsJOxgacCWZ5AVn+38HZVjKLj1poeWKQS2F0/ohIds8Fci+JClElFM4l16vKg/NDODiuo+fhmtnj44XeWwVAIzmHmLA4Bh/RaMDzJg3yy0na8d2WwABDqyY/5C76cSnbT2ECgDsM0RJEFPl77tTU= 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)(346002)(376002)(136003)(39860400002)(366004)(396003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(4326008)(8676002)(8936002)(66946007)(66556008)(316002)(66476007)(921011)(4744005)(2906002)(103116003)(36756003)(5660300002)(41300700001)(86362001)(7416002)(38100700002)(6506007)(6512007)(6666004)(83380400001)(26005)(478600001)(6486002)(2616005)(107886003)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5qvsSSThlztApITZWYnJgMil99a5DVdi38OXVbxEljg4GBFaz0OVeirdx5h/oFzwDzQWVnaTlOrWoJ0/9IfENzNksYa/sGiMsdeRgalyH6eUUnJ//6Qln4SgAthuCwS213BdIHPDaSRju+/2IgGGeJs9aHJq5sOV7YzFCA3lkbVOhTsMqVD5QybeR33caHAKS6yf2IU3jEcu5cx/h4yEPxQWXrxpExkQFLlYmTl9F4g/7LLk+wOBIiH2tfMaLTpfnnRO19ADPinGXaHjnNuQxKmf/9z6aWrZdq664rVFY414wIl7BYdaAL8luJH5ICsAihm08DqBkISLdZWi+d+xIMDK7RVr9RaQ8DVob+nHPsTU7d3qxWej1vQgSZIlFn7vq4IYzS25+UiBmwYfkoV3RcSoAosABfRu0DmYJx+zxlpfkWaq+BylNTuKaVVpck+pCZpSjz9pMohG8vwND1kc4Hki9PqPp4WsSJxDbrmJPnD+B7qS8qMaMDCpbVsgqAIc+DFSKbjDeocyGqQbl/GZGKlkXAt4/4NhpFeRuHhN3oFEappGHJQy4z0oVRF3e7T4TScXFrA27690MSW97u7150vXXbLlW6oGtt8YnjPkOE3adOuTNSuBmRcQOYp7rNO8p/NLbOjef4wr7/D8MpEKo4xIPz1M9hJqlH/LlHJ9je04SwB9/HvvLIQGXyGwH9j7n6dSwZt5sSsmXvvjhod6LAyhx7GutwZUzqXzOhzcn6fIRYjN3nuGvQ/6GutBpp4DE1TKboapKu/ZQZ2wo/8DnTTk9Hpur9/ErkgltMjYxbDbDIehrb/E9mvCdyEv5Ffek9BgoR22eUDMWFSG5m1WqBZrqTHzNOydNXRIaHQQyKKbDtYE9+swfMPk2bgAgHGZAMOvuseJbIO/+mZcnYYXA9y5BM8rsCRyMta1mpJO7eUeegbYVaYI6Qc6WRGWvYYOPg6gg5xcMCi/GHLX0ibVHFYD3qRqas7tGY38gGb9x9t07S8q6jPpFrFi52hTA+ycTq3aLZ99G/wR0Kn59coyX3jY1KBy3Vw8wLEI9H7h/QbojYDuNAvzQlFAbAhXgYp+xpXxFwBgCViut3Luyg5tS3OWjKl2y8qYPcYcekXG1DDG+50/s8E12hJ9B/EwmOiETGyLPjHVttNn7Gzsl/NThoSs9dMiuWgBTck9e4wku9H/aKFSc/9JBgUx97yTESqgki+rYxefVixFqr5XP8qADFHmhDheywZ/wcaZAwY77AtPfQ2yQG+dSA0X5Sx5Ny/SfKwCSSglRfYQHmiE7EIx3+RR5Zk3DX7fIHWmdAZV9o1naeSoKFvfQH4rPyWEqk7JvGXW8noMF39dRgs8kN8skUbI32wwotFy647D3YqkhT52PjChYazG3QhVJZuzEtWzsL11LmT5x8idk57AdU4mObCerkEu8CZwxM7yGjNLIJwYp1rlCcdaaiIYzQDBPjWYNjcqgNDeGSdtkycpjOIVVfvpTLmRkLQMYaknoqcqCFPBdBfoBsa114j12myV++s0ObjeIISt+ujbObPaN708jh5zfNKMBohniU2ROA2kceFCj2MDz/e+mwP1fJf4R6wHP2D6t9LIqdQcZFX0oI0dzA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /jOK+InweULA/4vuxnQNvdV2N94y25kcMUboyXtwhNpKx3x/+UAvKzvzXa3wi7Gs5ExgUT97ZHsPZs/s2LmXq9UmswFqSoGAyjWB6Mha2aSCv79mmqemRIii0oeAcj683mVVcPznxYNuZZqEfnQgxR8mfA1j8ZaovNgeueRM6c7x5ffDFBSgJAaERGI6FxYLt1Y1PCcKj9KzpJEHdZfWHK5w1iIs0pcuSQjYti0t2MxtjhpWsVGN5uRcfOz84/hsRqAdS0baY5uVTj5vxSK06v+24gdiFNjxEHNObhq/16YZN7gAZ2EM4Eb24Ht6ZDQtDQd68Oqm/jqgD+Sk2zZJkzumT+/3jpnz9PxrZWfDFSuoX/ynSFubcQ2rCJXvaa2vu0PdJ+MIS4M24D4MaPAQ2GfXWQT3z8LlhHDkJtzUCqrHY8reFm+knkZnyefImBEHJOGBjOVTInN45hRBNwt352ols2CR8on6d1rd5kK2lMXwi56nHjwWPNsGhePxvo/pd6jjBHNiT8X6VUppnCqyKgno0NhU/JJtlgP9KQ7g4NeQjfAKxWs3lXfhVUAUs1HEYR0Qd7xMTaelBPCJR2t8WWLeqy5XP/9bAHdBJp38evc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8414207c-901f-451a-e7eb-08dc1cd118f7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:17.3148 (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: tiBQnEcRjn/INR6HcM/fhualmkIzGF/UN11xglg9i8i23A2ut5xCP+OndrkQ8GYPRSa4IYiFNNZt2fZGLe4xlQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB7041 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: jY6U9HDvX8Vdjbo8dYcbm-Yo5BTOlyZ7 X-Proofpoint-ORIG-GUID: jY6U9HDvX8Vdjbo8dYcbm-Yo5BTOlyZ7 As the name suggests, we should not be splitting these. Signed-off-by: John Garry --- block/blk-merge.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/blk-merge.c b/block/blk-merge.c index 6306a2c82354..9d714e8f76b3 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -314,6 +314,11 @@ struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, *segs = nsegs; return NULL; split: + if (bio->bi_opf & REQ_ATOMIC) { + bio->bi_status = BLK_STS_IOERR; + bio_endio(bio); + return ERR_PTR(-EINVAL); + } /* * We can't sanely support splitting for a REQ_NOWAIT bio. End it * with EAGAIN if splitting is required and return an error pointer. From patchwork Wed Jan 24 11:38:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528991 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 E36521AACD; Wed, 24 Jan 2024 11:40:38 +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=1706096440; cv=fail; b=XcMPkHfR0wGQLtgeUyJu7wO2eDfjr9qt3b01YK3qMBZ+1qi5kIdP1uq1x5NQw2DaMp1IjGXGa2vgV1nJx5rnpabLRi9IOzxQ8CwDX63eoBjHqADljBVf3bpJ5g+q9ZXvSJ+zd5hpz/GudN6ImXgttlk4BsyicWcGDNdaAdcE5hQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096440; c=relaxed/simple; bh=toR9iL+t8mTkuO3FjPDFegghwI50RoiC9kcncLg0+/w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=FxYjtgw/syxn0YK3QVkiOPizaON47nwCwsvO6FCBt+ExEyXpdpp+Q7nutZhLwm3B2xpGA2IDldvDVwhCQYXEmQX9sH1GC3a9TVS2FPaIR6QybJ+az+z3mKvC17MFDpufzEGGzQCw3hfAgRiJ5149hy1ArLSMqoqcuLe1TheEzKM= 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=Ep0yv8y/; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=mGQGCCYZ; 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="Ep0yv8y/"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="mGQGCCYZ" 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 40OAwiDh019763; Wed, 24 Jan 2024 11:39:22 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=rGq3Yj4y89tvii5vJ2UgFo9EVo2/UqGJONVuMZeJncU=; b=Ep0yv8y/3BMU62Z9FQFcBu2l0RSOsdml2bK/+MXzwuzegwJFzIAsq51C9kPKAiZVHnn6 Ayfac1jdg5pEZxlgruv3L+MaV/T75SQ7C0BgZos0vVIttC8N9gflQXeZJz0/cRYuKlVM mYTTHy+0X7G506vB4N3RyO80f8t6cOKSTjDg7NOJnNgRld5+RrjYnFmVuGQrxCRBoID4 KaZggQA9+nO1zes4e3c5+UAmhfjCJ6k5RJ8AUdgjptdykLUAaGtJbmeQYXox5jbQyT83 qtcT2ZtSthjRXEtX36Vb6T9ALCVB4xy5rxyqVBshqlVGBa4u9d3hFJYh2T9JMEXaK6J/ tA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr79w262r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:21 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OAobaG040723; Wed, 24 Jan 2024 11:39:20 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs316wnws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A7HNqn9T0WJ1tCTKdrQOJWg4hEZ1G5iBl/ZEFmHLMOs/PB1tJU6R8L8l0idvjEU+TKXQRFoYNcftfSQMjD14nTjRV1jUdZsBKHTeeS1lhnHxvv5MpG9XrScdp5l/ayog71huGQthAgGGRwZkghA7rEehKF/vnEq6shEL5xEIYWlIdu2sNJPs/tSZ2Ce1kzkxn+s0pDSNLQtr31aocRCeio7emitwh/Pq0vcqP9nd3pFTSuUoDPpthTO3NkehzFdTr7Jh3XVetMlWYCn2qctFCrFtfi9NFd79WX+CvNzzs4+LqPiN4M4LpOz44uviHaa5ZKYSULx5nyK+O00SQRYzvQ== 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=rGq3Yj4y89tvii5vJ2UgFo9EVo2/UqGJONVuMZeJncU=; b=Y+afiYJ3xq0DOtwsIg1x9E/THIDRxewL45YO0u/r2KqNA1mBUChPsa8YlkwV8ZYEq8pjaf4CBRnrjZyFSlnXWgRssEcjqxKMOJI5i1S7rL7rfBO1Dw4lXvct8TBp5rfRK2MDaWdxpKryktLx2OOfaA3bNrYU4jCIJ76DXaC9KdpnBgObhpeL4HJqzDJJDx/idXP+/TdENKit9zRDj2GsjUl7VWU4u/v4PTo5Q7s9v8y9Q7RVKUKFr5gSq+W8mnIRu9QFsQFvvwiTz1V5P5oWaKdfo/RBdhi9q2XMDmHI5HzU9FeI9TRN3WtW/NnQMoT7H79DenEh9V9sNxUrPpynVg== 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=rGq3Yj4y89tvii5vJ2UgFo9EVo2/UqGJONVuMZeJncU=; b=mGQGCCYZfWDFQZBCXca04Q6PV5kWywHVMskulJ6BliEG4g9krEgkhkAy1entRmPtgGKsBl/qLJBXGWfF7cA/NNnNwlE9ZJQSEI5LQZlhqJI4L0WSAfQ2gZDPO0vNcnzziKU1Mmcw4kediXU/LU56kidEEtpt5wRL9aIeeg5Yjik= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB5815.namprd10.prod.outlook.com (2603:10b6:510:126::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:18 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:18 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 09/15] block: Add checks to merging of atomic writes Date: Wed, 24 Jan 2024 11:38:35 +0000 Message-Id: <20240124113841.31824-10-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0121.namprd03.prod.outlook.com (2603:10b6:208:32e::6) 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_|PH7PR10MB5815:EE_ X-MS-Office365-Filtering-Correlation-Id: dc8d8779-026c-4bee-b4b9-08dc1cd1197c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +MK+12SzSZB4AKxY4bV36utNtxAeX32W2B2jrAv332fVnyfWBVydD13ZfFuOv+UtwcMkwhr+aHFBtiB7HBWCEwfnFEL/yn5o0tLykhxjEtCm7oA/gKC/V9fLb2PyZteqp0MCdqhQKvGSselyi0pNo3i6IKRFLK1TsikAwthfJd6LbduUYRpCVbd67ebfnXufr0x0oQojy2O3pZQawbJlxzU6wCKOfFfkNCkz+8NbWHT5nm/Rreoeg+GfjEFEAVJ8+GaeyVdTg+msu30GTP+yxk8Sgkt/IZmRuD0O3zdsGdun9OIeOHua216zvuBjIL5UZBUvYOJqLDLKnm7blEH8HNkyOcQcyfzc5ouE+nvSAXSs/rG5veq+e6Mn92RS1VuNZ2ZEIDQ3Z0NqmdGAXUdKMuHf9vyjwnCWM2D5BuPQhYfITXzYmi+MeeGy4hCgGCuL9ek0/RgOrGuEbUbxrQzskVOnPSWvkofZ48d/ksQTGp640FTwEFLwhrpC8B3inbUAoEjrubS/exw192ekWIegm6xu9xRVZdVBwqgDIAO0aiWz6BmoxT/y99TeFGSEhFC7BCHpPFnafDjfZ6qq50lGj4IecTgQxZ1pyIuGryhqv6E= 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)(376002)(396003)(136003)(346002)(366004)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(83380400001)(41300700001)(1076003)(6512007)(107886003)(26005)(2616005)(38100700002)(6506007)(8676002)(4326008)(8936002)(5660300002)(7416002)(2906002)(6486002)(478600001)(66476007)(66556008)(6666004)(66946007)(316002)(921011)(36756003)(86362001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1hVAsKXNDcs409w8+bgkdinSa1zrRZDZSurK/N3sUsqao6aA8xftejCn6coK8SzDoouPuA41KC7RzQ/5QEhkes2MF4D9FIRLhp5EybXhm0OG2rE2bIwZp7d8cNxwXG8zFbuVzVTB4UBtPhLtqjEud1rqcG7UkcB8crWkq6EjIRmOTIw0oCjZY3ROlctngR8RhVvtVGCvyn3L5hJ/H/eKog0U53ccqkz/wqDEMNLcvVsZYF010XExa2fCyHtDe9Xv8eigbGMFXL+CxrBHXz0y4Wl+rK4I3OtkmUO7tcH8ccn4RCHvRu+fLUHE+Kob4aP5sVQz+aCP1Z2ZfrUjX7lhJ9UkSPBnpsFlwwznzajOlZEkyopdG4Zh4IwyyG9kbjMsgI2OcJ47NogrkQyU4cSI05HKdB1icHg6m8PDSajSADicAXzcCwLm3048KIsr8+nXttlCXZlm3k/GlRRc8nlqy4A7iy42WFTdQ3ht4XeLWC3Uv82s3jwaQ+sWVpBzHg/42fQ3ki9VpGWEvV0UKloBlk1NANdinALXuaZwo6Q3cyH4YMNlVovBft4fwI4dt6h/KP1FrGngg4St15X95zmmv9zQS8d6lszXbyn8SydbFvmP6sD2qiz1UwLX3dUFeDJGUPfFv5leckF/ImjK/mN8aMnPFe85Mqa+Cqgm6AwJwYNTqLOkhxoAVICk5VfPsijqOcLbAhjTY/gx8SQAuyb4SRrAfqPV8GoXJpGmU1AynXSortAJl4aC92+JY/PaarNbeWTkAAO2iHhdqkmu80vWOG+FlZMfWbwoIs76anMqsqxJk9gmfff9ha1iRs2mBBlQorYmjBqZBTHHzr2FBJ/akVjjfwrE2GKWpMcWvWv1CTL+Fwon7iyLgvSQrQQXrj2EZjSjRIk2jwjoXTvTpywuzbEFDknbAxdiP2hK6fcJROMtzVgIyBuX2F5g9fe+a/iRDB0FGA0LybQUHqtojn3swcejlCucTx6xRPhWo/cfOagIkWc7eRjnS6r6xh6fwnBHiAHtnCHcsESmEL4s26smONfkqfkcrt6HwMJjThk/JLkzLKAb40idr6IB9BWJL3mmJCnNHk0bwIRR7E1dONRtQ8HOdB8sfR5xKXYvbK0hiCcBXSGR06vNwu1LCkt7iprMgf3bfHKHXzdqVDushEnG+T/7qVYG3sIgwRTbTWsOdCXjahdz61XUmd8yn+5H9FcldBM9ROS+wDHx03La9Q8rQ96FTZc5Lz25c+fXkZW9euYXFw4tRwp/s2rRBztdswdsIzUj75W0bcwpFpHVMzLaieFDmwqFNCMAW6ImqCK2rrY1Yy39snEOco0bdyKv9ukd+9ng2P7qqS5jrdfdaT0IPzEQt060he7WrBT9BS6U3tfiBKvmsnRcCpBArbbM3WxOgLdRqCFhJJSjciQIsolT76B9ayTGaP/BCrTBaJ4NZhfxCaTQY3COFEKi+0ei1W4LkI6/6+W6+vfpBLCX1rfvTDKYUlnEX0hsrx2Xwbk/OLJ37auz3acOsq0hkuDd+LjgbuZyyFKFvuIicSMd5Ap2b29/LFLmgLFWVMFAgTa5rtJIb0fj7vDTjJL74vIp0xkV1/HjGo3ewDBptIVajC6DLg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tPPP3TySyWrOgWk+8r7QlKlyb8DD7qL4CAaiXh1mQnqMiRtVDeRM7Y/gd8QSBEHGJjZtr6ABmTL8SmxisRZPcMqUyR2IPv1G65NlsyG4dPMCf2/Ho0pz4+0rkCe5bxfFbshpFQLg6BksWIfQ59ywDgQ4tVTDRWkSvYqx5QeRBaJ5nuKtSqJJ6q6+5WOIRd25bGWK5CAYf6QZQDIe2Y09+g+cA3aXU5MFFedhI66dtPKo6VsUumtdtf9hLbHHdzRaSfiGdlqSrr8wFkZAXmckPlnfdBIVFVlQlEPHSis5+ogsJ9k1i1LGGqfhk+QF9ZBs7hXd9iVj+2QNHXJoXpM8cmB9pXR+dytGhv+bP5VzttyRj10+NzGBkoQqfJrohov0+mYljshtEs8krFvS+f6AtO/pz6eZqdaXO8Pmn7oeWm4/ynbeDstIk3gFEupmrwjdB4HkASReR15HAGbruOkOkCXDB4EhMrThT7z4+YaPTQ98IjzUQ1lAhzrILiGAW5z7c1R7A8SasSX4Rkm6FlZ6TJiVBDcA8C4nMRCH+v8DkXmI5ArjFonvXS+ExKFlmGMAeaf+5qW1PUsTQ0+DUrxdxdoKMqpCtsi8UCxTfj1sznw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc8d8779-026c-4bee-b4b9-08dc1cd1197c X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:18.2475 (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: kKcOUC8gN3H2yZKyv5m1iz6WbxmiaVuITQIqDRCHtAek0MG+kFmZg4wMClAzFFZc1wGW2574hizTd2+As/uN6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5815 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: jSlye0d3cZdXEi0fKdQ_QJxaz5ZuUHj- X-Proofpoint-ORIG-GUID: jSlye0d3cZdXEi0fKdQ_QJxaz5ZuUHj- For atomic writes we allow merging, but we must adhere to some additional rules: - Only allow merging of atomic writes with other atomic writes. This avoids any checks to ensure that the resultant merge still adheres to the underlying device atomic write properties. It also avoids possible unnecessary overhead in the device in submitting the whole resultant merged IO with an atomic write command for SCSI. - Ensure that the merged IO would not cross an atomic write boundary, if any. We already ensure that we don't exceed the atomic writes size limit in get_max_io_size(). Signed-off-by: John Garry --- block/blk-merge.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/block/blk-merge.c b/block/blk-merge.c index 9d714e8f76b3..12a75a252ca2 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -18,6 +18,42 @@ #include "blk-rq-qos.h" #include "blk-throttle.h" +static bool rq_straddles_atomic_write_boundary(struct request *rq, + unsigned int front, + unsigned int back) +{ + unsigned int boundary = queue_atomic_write_boundary_bytes(rq->q); + unsigned int mask, imask; + loff_t start, end; + + if (!boundary) + return false; + + start = rq->__sector << SECTOR_SHIFT; + end = start + rq->__data_len; + + start -= front; + end += back; + + /* We're longer than the boundary, so must be crossing it */ + if (end - start > boundary) + return true; + + mask = boundary - 1; + + /* start/end are boundary-aligned, so cannot be crossing */ + if (!(start & mask) || !(end & mask)) + return false; + + imask = ~mask; + + /* Top bits are different, so crossed a boundary */ + if ((start & imask) != (end & imask)) + 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); @@ -659,6 +695,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); } @@ -678,6 +721,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); } @@ -714,6 +764,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; @@ -809,6 +866,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. @@ -828,6 +897,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 @@ -955,6 +1027,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; } From patchwork Wed Jan 24 11:38:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528987 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 984E050A8B; Wed, 24 Jan 2024 11:39:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096386; cv=fail; b=LsRCw8cQ08s5/5Qt58lb1X8Ahxn7ba8jvVBH2XpfWxrONSBQHJitLv7nyITHQVIYo4Rz/PGG5Tm/rXPYHQHY12jmwwl+eFrWr14ZfOUHXvFIf1iHunOeRJsvCofHPioKlbIx6WgUE5Rdv3AyvUnlDrTYtsn3WtwV9q/qGWkz0wo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096386; c=relaxed/simple; bh=LLgflnzDfZh/eGcm6r4ptBZvmUO2fCiYcgNc+1tZ0u8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=LknyCHtw1VY0RlfbEePJzyjBTnzrMgQ7ZwEop0w4o2xIYZh7qwe2cUHJS/BnDN6HK5ewfMAdHFOUsIs81p2iICIS/TwjCCbafy3mk4CkjfMyzTvIhqe6gEmCeIZe7lRskRxBZPZ18Hko7fzWqRPPZbGp+nvPOafqDCPbZn4FLCg= 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=PxRv4HLp; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=fooCP7Xz; 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="PxRv4HLp"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="fooCP7Xz" 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 40OAwsYQ009416; Wed, 24 Jan 2024 11: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=N33x0AgmSk/inaBUpiL120sCppRmMyE4ZMGnb6eay8I=; b=PxRv4HLpSCKP2+RIJYU085jeZYVeyCfMxhs+QgHeS8oNFX2LmLpuFWUczPRecLziejxW cpH3RF53Kk4yus7+orBuIsYQRxL/fITz0vUEHiLPOsDPoNsEDXCWzPbQiPmHILzo00WN RqrXp+JTzr0H+6F+B2uN74lBBwbn124M51MY59DxXTdgOKbFn6wIukSpgDjH/zF44Ps+ aNnT8o/Im7J1o5AQSzHBVeC8axxHPuMe9lZGWAXfafFZPsXQNJBsMBlG7dTsZxywwie6 6BjyWWxnaWalyxGBpWLH3t2jVCCusdK+M0GFfJ4BMaQiM3Owj5ZDFqDCHZ3bafu385Jp Cw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7cy1tx9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:22 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OAobaH040723; Wed, 24 Jan 2024 11:39:21 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs316wnws-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S/Q/parSJ81CHCpuXlsLr7b0RuDyIQl5Mi/eIC0LF73W5z6cNE7AME0kgLEAqPWslKDi2QXF0miXM+NQGa46/gp1VrahjeCNKXtF39UJ3nvcrzccNbdtxZdxlgGXVytqagnTPjEHCktT1uMNjYeD80G5aYFo/g0O3r6iq7yux0t+Ikrn/DDlhJgm4ItLTxXC2gqvIo6+OC1LoLzwXwsRld9PFCXUbNWBYnWYqMI4gZyBL0EVgezSdodPYNM1sll628ar3dQwo2IaWhDPxULxFYQXddKiqweOlqU5h71DnZyGxPDaKpP16LynpDIqIiscVQuYJ0Sy3ccyJn8N2RL6CQ== 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=N33x0AgmSk/inaBUpiL120sCppRmMyE4ZMGnb6eay8I=; b=JI6TwBB4N+fw9xTLNY2/nyDGC2F6SZ0EWTnAnGjy96pV1Ihf5Ml6jFmBMrIwe1YwBnAsgVtGbwiwaUUvZClrEvzYrL0GD3+NgF3mr4OpTil/JnsfwH/QFJY/m7F2+rustbXr9l/v8J+tqnSFIMonOguLXpFisUqt+E/gOXkJCpWaQOqwJc3tneVzoIKQSFQFJTLBVplmi9rhAMITSvglWAmzGjO9oxZIZzGO4z1llm6nGFrQbEXRhIH6Uc/i3odKhXleYWW+KTlByemgtuocDIAgo+7QJiw25z7/hmvPqfWHROHZxqKOaYVaDaaN7UYP4zyvw2syZexB8nyqq8bjZw== 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=N33x0AgmSk/inaBUpiL120sCppRmMyE4ZMGnb6eay8I=; b=fooCP7Xz957AlBEgZ8T9rnn6BAeJwX0Z4Ru5HxVo7aLB0+8MLijXi6GKjfylC0BNpQLKchkZ6/ZZd3pNZ02tSYfpoYqdl36qpizk2f7EQvpdgODmMyDW7ewcp34VAzX7fWg88WxRp/wdXNfBbxphPHRnqkeT3MOfba409DhBytA= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB5815.namprd10.prod.outlook.com (2603:10b6:510:126::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:20 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:19 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 10/15] block: Add fops atomic write support Date: Wed, 24 Jan 2024 11:38:36 +0000 Message-Id: <20240124113841.31824-11-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0158.namprd03.prod.outlook.com (2603:10b6:208:32f::24) 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_|PH7PR10MB5815:EE_ X-MS-Office365-Filtering-Correlation-Id: eee08816-ee24-47ce-5438-08dc1cd11a68 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SApAgXlyQUNV8N7Sk7PEW5YN+Q5F0IGH6lk/PmmWcgKqfJYF2uweFTTDb1Zj/6JRHBl00Kji/YBTblsji1l2YQoHNZ5Pwd2CCrNXFuZaKHC/U88QF/HgucbZBZumjLrWCqrZru4FZVunHL5TIC/5Ie77AvyOMnuFcFyUvf+TTXy8VOaAdYyqF8HazEYxtQNNeIfBwsAtgKhOnq09w9DZlq21CY1Hum+Sz2/ke1zpmhrvXm5wWDY3CCb6rYKhWsCrEHq4Y+L/gm5QPjBhqjYTcU6K6pzpsB6952af2WjajykyWQnFH8yyXQHApW/OwabfJcijjkeQrHYO1wQWtCPGKZwXikwo2jgR82/Q81BkZBdT/geBnx2Swmlc7uWoV8wM1OLhtJNLQ471Zsx/5OCB4mechJ2l7d+rvAQMm3fEnc9IMz5sKmTD36h6AnDp5nnEgAU/PB0OfeS4ZLEjayp7JF63tuJB7tTUJVsd8VL1SiB1+YZ1AKo5Pilk/w+uQd5qraocXPGP7Ex7Q2DBVQ216gLBPgtbyxQ//4Sig9dJ1tEy+AQR2IptssAm6hlR6zPDCie76YG4++WiTELwhxXe9WIzRdxB9TnF2owQuViliX4= 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)(376002)(396003)(136003)(346002)(366004)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(83380400001)(41300700001)(1076003)(6512007)(107886003)(26005)(2616005)(38100700002)(6506007)(8676002)(4326008)(8936002)(5660300002)(7416002)(2906002)(6486002)(478600001)(66476007)(66556008)(6666004)(66946007)(316002)(921011)(36756003)(86362001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cazXGbIxvpFCSnfuWUJnUNutDhhOGdeuMdQyp6O79biCnr/0M1CD62Kqu/6BcE9S6oSuKkic5mczrBAUmAIPQOZmWv5a8g6QF0h628gWAMsHA5pD2HI9Iq7vum97dVfDPzM0nNZ86LA55qvXqvHi74MD4GUO/ur4IMAXNriQSVtf2QK81SXsTAm4WxKUwt/kZCxm4hxoVnW76JikWCCaaIW9rQU2PFHBouo/Q/aVL+P0//rDdixJUFeFyn0GztI9EMNLB7b5Ksga9TtAiTUc82jIYHVIjnXE/iqwws6IYnnYGuG8nRh9m8Bg4Nn6C8EH7uMd0WSAhC++iOmVypFpJX72/3MD5IBPACNzlXPMuZeAU2NCmnd167iQVgJaJYRmNKFmOto//fs7w/WP6ks0CDZGw0kfLkOugfszcvg3JEbtddmlgZ+xbJXoF3LTuKhzzqOJ1KpsgVZTHpoGdi8tJ6cTvz1KNrT9TZi/B/XNLdjbRRrmqMz7dd+Xzuy8HHdld7xUd7j7fdMtqr+31o73azdSmrixzgfzI1aF4/CN/TVV1wqszcRJicZsnIgDav8YvyL/B/rnXgcHQaoZWOwhcraXah2h30ZubIQlcUc9ciU8kKvziZXpG5T1ZBvIUKw7yQ7euCbCIFKelajUlmPG+enV+XFeYFupvf7qIOtaxRXTsXldlQ14m78+3atnYa5w3KFa8xSydsfiYeKaVnGZ1NHYBkmxotH1GhxXH6i/jDh0fxrQB2CDzhEjYnzTE0zjwQ3q/aga4SviqH/fq8ofjCZobg6+Zgo6TMXiCJTJL3b2VRHNyoGav1tKpJ1+KFBZDt2plIkV+ybYEySjJZrv8eP+fsKsds/TL02eXOAYunUhzPhiGqteS36anX5+qgOqCCi5+wg7ngR+et17ofombu0rY9MXAYt1vfe/cX/MDwHbAWXsGkh+ePFkTfFRkn1x2oJNasNwjUbTQnYVzehsPUO5RTye4fCk763s1Ie3mFoI8N3ZmxP4QPGYpMPaAbGOBo82+eXMuWV7raI4GiBt4PDvU8qhchYaFcnykN1FrCP6ZaehJ0oIpLujQYPyxF36oyjWrX35tAASgzdZT8CZYMMWvaW1dTg8xQzK7XABMC/ggV0V7NbRtclEpR4Z7C/bfUM/9UdFmin1IksovAj5vXdYNz9U0lVVZaQtF4l/Y5hJDVWYPggNLwExQZN0wq9+L7iEuYZzLQVLRYquyyIJxxlgJMLlUoEULsvzgcTDWdQlL4L2ihs5pfRCXppPyogfcxT38x2lO4OSfNOPna0CFAAIHnndhh6W2UbLFiSyusATA/LkYERO8cGnPn3Lg0rXD7eagu2hbF0tJfukDeK5BwtOBKk5rjZyW2fveDXoqon+Pdrhr/M3mN89L5P3upxI7gt4LpJbrYFy4c8m1l3HBAz9MxvzIA1a3vF3zokXSiVc80K3fDpdBwNM7oCFYk9ms6c/l8Tkn1V7hf8LbxWyn2A4pCDqfCkRKh1jbR5U5MvojTiI4X1mpoALGmwyEFoAbGHROUYlB/8uarzTvL3UvOb4owlbAztBDJdS8C3tHLbsnMiRV+99D8J2KU8JFw9QQwYzncNVHd6a7siNQEEloQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: S0Z+EFQGi/ou/I+7+lSQKOJL3U6QItNmRlOioIhoWznuwj20lsnmUfh9PWfEwMfai0rnCeDkTszZWyUwEiFuuvUaXVPa7wEiHuK+XCCRKsWpg4/DUpG3erRjxggxP55SvrgoNXHpDE78cnkU7ShoHB3GRk9KjifXijbP6IqympQJOXulvYZKpN6zjvPkrqe8oQplh22+bPTqd3rrK49obfFjOxZgdkRuB7pxb+hsTp+3kkRdMh5eakFdNrWA/0fzCGiRqhRJgLWMrb+L3wMzjJx97UpUsMY4BNCdwF5Nx+5ny1+U1wJFgu54GIxiGlOaAkGTJTXM8iYzpmvSqvRj8Ok/48ecLtpakRsF1CSTqENspfg7CIm5Wf9A4IqSOMSX032VB1OuLZpm5MVXt3T8EUdl+angShMZf0LzJ48LDjJsVH2F7eqHi3Z59J2Tpj/r073D+00qZx1t8NkeLWeNTOg/g6nhVMAW8Aq0QXiwGO1x+AJYgFix3DnyEDgi6bXzEUXLQpHPhZQ5R5NRdMVd/euZxu8YtBSAp34cCMtloRnpFQneBMx+vh1aH7CBv7e2Oa9pbGmYVD/CYr1e8uy7FraXgp4bfU1B92+JZUNpfbw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eee08816-ee24-47ce-5438-08dc1cd11a68 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:19.7836 (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: eXDEq8+A8swuEflb3zOMTI8OdJ3skLsNncSRB75NslFnfKHaVLJ9gwFnkBcaP3rmZeMspgClT8yEdkQqeemrkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5815 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-ORIG-GUID: e_9dzEjHk8EU2avSMx8l_zE45bN1TrZM X-Proofpoint-GUID: e_9dzEjHk8EU2avSMx8l_zE45bN1TrZM Add support for atomic writes, as follows: - Ensure that the IO follows all the atomic writes rules, like must be naturally aligned - Set REQ_ATOMIC We just ignore IOCB_ATOMIC for reads always. Signed-off-by: John Garry --- block/fops.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index 0cf8cf72cdfa..9c8234373da9 100644 --- a/block/fops.c +++ b/block/fops.c @@ -41,6 +41,26 @@ static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, !bdev_iter_is_aligned(bdev, iter); } +static bool blkdev_atomic_write_valid(struct block_device *bdev, loff_t pos, + struct iov_iter *iter) +{ + struct request_queue *q = bdev_get_queue(bdev); + unsigned int min_bytes = queue_atomic_write_unit_min_bytes(q); + unsigned int max_bytes = queue_atomic_write_unit_max_bytes(q); + + if (!iter_is_ubuf(iter)) + return false; + if (iov_iter_count(iter) & (min_bytes - 1)) + return false; + if (!is_power_of_2(iov_iter_count(iter))) + return false; + if (pos & (iov_iter_count(iter) - 1)) + return false; + if (iov_iter_count(iter) > max_bytes) + return false; + return true; +} + #define DIO_INLINE_BIO_VECS 4 static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, @@ -48,6 +68,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, { struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs; + bool is_read = iov_iter_rw(iter) == READ; + bool atomic_write = (iocb->ki_flags & IOCB_ATOMIC) && !is_read; loff_t pos = iocb->ki_pos; bool should_dirty = false; struct bio bio; @@ -56,6 +78,9 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; + if (atomic_write && !blkdev_atomic_write_valid(bdev, pos, iter)) + return -EINVAL; + if (nr_pages <= DIO_INLINE_BIO_VECS) vecs = inline_vecs; else { @@ -65,7 +90,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, return -ENOMEM; } - if (iov_iter_rw(iter) == READ) { + if (is_read) { bio_init(&bio, bdev, vecs, nr_pages, REQ_OP_READ); if (user_backed_iter(iter)) should_dirty = true; @@ -74,6 +99,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio.bi_ioprio = iocb->ki_ioprio; + if (atomic_write) + bio.bi_opf |= REQ_ATOMIC; ret = bio_iov_iter_get_pages(&bio, iter); if (unlikely(ret)) @@ -171,6 +198,9 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t pos = iocb->ki_pos; int ret = 0; + if ((iocb->ki_flags & IOCB_ATOMIC) && !is_read) + return -EINVAL; + if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; @@ -305,6 +335,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, 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); + bool atomic_write = (iocb->ki_flags & IOCB_ATOMIC) && !is_read; struct blkdev_dio *dio; struct bio *bio; loff_t pos = iocb->ki_pos; @@ -313,6 +344,9 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, if (blkdev_dio_unaligned(bdev, pos, iter)) return -EINVAL; + if (atomic_write && !blkdev_atomic_write_valid(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, @@ -350,6 +384,9 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, task_io_account_write(bio->bi_iter.bi_size); } + if (atomic_write) + bio->bi_opf |= REQ_ATOMIC; + if (iocb->ki_flags & IOCB_NOWAIT) bio->bi_opf |= REQ_NOWAIT; @@ -620,6 +657,11 @@ static int blkdev_open(struct inode *inode, struct file *filp) if (bdev_nowait(handle->bdev)) filp->f_mode |= FMODE_NOWAIT; + if (queue_atomic_write_unit_min_bytes(bdev_get_queue(handle->bdev)) && + (filp->f_flags & O_DIRECT)) { + filp->f_mode |= FMODE_CAN_ATOMIC_WRITE; + } + filp->f_mapping = handle->bdev->bd_inode->i_mapping; filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); filp->private_data = handle; From patchwork Wed Jan 24 11:38:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528989 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 E51EE51C23; Wed, 24 Jan 2024 11:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096390; cv=fail; b=Wd64L2a+hVTGBBTbnO+4s4zrZrLtYf7+/kV8UsHeHaFS3n4f6Vbw7wV16f6WxzDE0blNWIXgIkH+OHZKYwth6rJ9BMg4o9+5zBSmUo+CuBPfTTyBezOKHPEqYVlQAGwuFhe3IAGOkooR54TUjvZkmTMV+nfCvq0FenDXwPB+9lE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096390; c=relaxed/simple; bh=eFg6jr+Oibq2mzMwJhGbbhShznIs2nlGxBzxrw2YSSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Ne3xdI5OE8xNMas6tHLVM71Tzj6PGJUZmSPcrNarVPttbn8ItsWYZGblO449zuh3MfWc7sJ+PBmuANKxp2qfwHa9Zd7yihDHCxHaOIKTK+MoK3Ad+gUFbFWri/FJGJXnEsU1RoEpyKNU+IA8VcXUpm7hiv/2/H7VddBp6w+QzYE= 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=N4nqXPke; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=FTIMSkts; 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="N4nqXPke"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="FTIMSkts" 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 40OAwsO1009429; Wed, 24 Jan 2024 11:39:25 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=RKRautNLmAPG6+F7edPvHr2ITNIVpM77Jln4UIZ5mnM=; b=N4nqXPkemLTsS4oM9RhcqsyGL0WQEFHW7FxgZN4Ow92iE1/JbVN9J7vRS7eWi0EtVVos cyznZpxZM2gB2fDWMeb5H/CEvKAscCzvKaVZdJhUFLiiQGgnmjl13caFRDC22T3LcoSX O1yr/pv0ZJw4qwyPfvLdXcqq8uJIme1GRQ39VBpdLUXETmjbVvGZAVidwAXu3/iUFnMR nQBcet3FEGg1ho1E2JdYabHdkSB1hy2DIQnn+emSDoJeZ+/Tnmj7CXxw2IjLVU2ABUwt LzKAS/0+oHsdzHu0owH7bU7tFJQcH0Yfn5m3rTpEiG2yQDRIxTroTTmLxEtlbkF7ZtTb Ag== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7cy1txy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:25 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OBKcRq040865; Wed, 24 Jan 2024 11:39:23 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs316wnyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gi71ihX5oNhS1x8inD7BGEZjJBTEIxHSSxOggsRgQyGigYlqEWR0Q1tcy4+w6HVfcTx7QQQUkqN8/lvzJxHbSfp+huKDkdkWIVgSEZp5e+beLMoUmKEw/+J1w+NLqG45OWliUmTTqG0WYzDdOXIzBYFzByRfjCGgM5pbbHLANMnBYfenWicmG8v3uC4E3rE3hp2qicjgAS9zpZPKYkjAX+WWVJ8VhDXD1E952gvB3VdFq0+UkeNkaxiWnPgiR5S2L9YKxRpKKXKJ1A2f2VMlnqj4nsUEyZKp9U0C4JcoGuj/mNeN9JptVrqFhRDC2vahAee0rhPSpzF6XoOSlZmkSA== 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=RKRautNLmAPG6+F7edPvHr2ITNIVpM77Jln4UIZ5mnM=; b=Ub9mrmsSODpFWy4oCDyIIaCMADC5Pa/5TM24wRnUZ/Uj2Bl7G4cVoF8bS1NGmKBle+rgoyLVtpQw6c7fNt3N/apYtEpW1mjMrpOZmOetzctHwyG3eM9xPvVQjXxAJVcYkfZtJDox29GZmgmGIPReZQ9rMj4WMGwCrqh7hOFbjw2thL7IXRajyj0K+F/bO0WTcS+5mUsR3A4yGkDmQ0xOoiIbzhNDoO1VLxoStESZRWJBXRte8BImo7QCAMKJPHJqEafPG68Zkk/6rQpKDATBtpwWG1rrQ+/yecITQx3geelLFHEEIf90r0yCgvhVML02StBKn2RkPshDDtTlojYM0g== 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=RKRautNLmAPG6+F7edPvHr2ITNIVpM77Jln4UIZ5mnM=; b=FTIMSktslLdLgUcnG5GuqEW0OrMCf8nnGPU4u4lKd3RCZ2kXxTVteken4I7X/3vhHwk1P1PoyPzdpSBzZ+Qge9NC0dJhZhC2P6GtIXuihC81IZqqFa9jtyiprKTSc8BihYJ0pKUXTBmXDKR67NfS/Lo1H5gbOlraO2vUJi9TrPw= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB5815.namprd10.prod.outlook.com (2603:10b6:510:126::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:21 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:21 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 11/15] scsi: sd: Support reading atomic write properties from block limits VPD Date: Wed, 24 Jan 2024 11:38:37 +0000 Message-Id: <20240124113841.31824-12-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0158.namprd13.prod.outlook.com (2603:10b6:208:2bd::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_|PH7PR10MB5815:EE_ X-MS-Office365-Filtering-Correlation-Id: b207b4fd-f9f1-418c-8ad3-08dc1cd11b28 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dy71tp7IKasDqHl3dCPhOUuCK5p3GERVJLcLliW+f8Tvg4Y9t8XD/16VAYc7p+K7MQEQZORmp9/C1SKSIL+zcgxxQ+wJGPeXfY1ydmFPqoAJ1z+czFcCxKDGLi/N0d/owSYjojHedSMN4im0KQa5PSk5jbt4KWyjqYMqawkHKqqQ9s1XAL+13EzzlqRx05ORP8+J6XNzL91yA1bj+Iq082k/ZR7pIJBm5rUUzrSn/RcBQr8LQalglLZSRTT6oYas9LQmtXn1xeliXLlScaBLcYlzTbt7Rh7dSYBFs2U6+RU/EXyHCa0WEhD1vchFKXus+un6dakKPkyDgmbzXRjAyHLVt1pX37EKe/ER8nwSgifnFyE5BP1X60CALQsS2LTjjjiACizAsJ/KCtxcDHHFAZShxNcOXtbXvJa3HvY4uZaq0CoTCOSO348epM1y2wh5rsU0s0brXqhsvpf4da7lvm1F1dHQ0Geen2aZmPQuLMYpI6beArZo7QikVfsWvGcVvGEhEmdkmpifI6WQ6UihuCiRWXQleSeEaNbO474HKcQ4XEmHd+IlSNikdaWTvBoEqV1Mr6We95HJe+MBHvbA/qvGFZjROyeYrBljrSsb/uw= 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)(376002)(396003)(136003)(346002)(366004)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(83380400001)(41300700001)(1076003)(6512007)(107886003)(26005)(2616005)(38100700002)(6506007)(8676002)(4326008)(8936002)(5660300002)(7416002)(2906002)(6486002)(478600001)(66476007)(66556008)(6666004)(66946007)(316002)(921011)(36756003)(86362001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bRIlaH5CJnIexgw23W+LQuKa20xtL65uYEfsUJRWplnWQuoTa5WxgQDJngt7GoX6cBB+6qHJESFTXdymsjoFzhCYIPBU7QxeEwG16RsJmz95SGivHQQHicEMRuvMuuQ6utxx6UJkDS6oLdvbDrW3rtHxeofM9PZbtEnk9Uvapn5kgXwN5zjTexlz8mLWlAY3PGhFpY3VdsVtFJnxRbe/sp4JFa5F+3H3iL1HaV5LpXoSNi4w3g9hz08JHJERb881+P6O3NPvejtOEG1vhGjg0qWd7/RoqCnnkrxQGFZulxW5YJtY5+XQe22ckqpxCR2MhwdnEyTw8ajlCEs4cyp0uQYi0Ju8O5a0xdp3Tnf5k0izSNboP1l+Wkw9mUhVdTYfYWI8IfTgp/JPZfx0/t5zs45kTz9SfQuJ+KuOIASPRTtPbvFnZPT+4HXmOy4K4+3B4lbCFOiaMXswmCB2L7+Ptg99mUtcnQ0WFNbWuW6U0iJxc703Xy4ESfmwiwhuL/f+6C2g4j38uFHxKBtf2J/REKeyQA4gs6kDsN5J03JeooC4XzwrSSeqQjt0tCtlZNmI9sZvFHKCBvBYlsU7UFBGmbt8f8IoCDjBQIMhezhnDerFUd6Aq4xfmbz2WY6lACXv6abrR04rqMAe1sfYfKabNMgc6ZmPtXPfUrRiquJmXYZsrOdz3gWS/EAJMALkUhfXFjGqpspKn0V1em8oVgarZDpJS75FFnzjMgy5jkrqbLvkVlgNjm2ISsPTV2bKDftdYr1PI5Loc2B0sKTr8goqspG5VriUEt7BbQWtenIt0fDt5hie2Y4j+gNKa9s8vElTVHej2/tp7hlwcYvVVS81mnEnkQY2D7X+NpBed/8z2wEOM7JOyOOKe+KEWctE0ATpVg1OM5lhk1t3NDNy73nFvJrqNbyW4lfD30OB8Nxq27lRw9OyMWa6fSZDlKBFcXWlDRlZkEUN1gbh8mT9qQRdILfPE4LWzb/GIEIeS9gHTydUtu+Qdl69O6v5k+v+qZXsRzOSG+Fk0jJtH+jQ2kfk3YqCGSQfWZ+D7jR4Q9H6n6UKAraM0wISvnsO7/9sQhbCOsL/hOpba2s4KPn9gJ2rEQl5hio/mT4Pk3ZdhKC8LDyKOPkhKtXYNheQY82FJUEP3fkujtMoyZUX+pe3swWoFiAuuOG7YBoEDAjrBH5HYuaEvpRMtnr5Sh6g/qICgXbSSg5ATiIr3/kAlloYL++aHTyU5AVd0QZ1JOLSmXGj9i9dJszIGFUTlxplOalSzgV/giXedjq0qHrCR83CDyNofHPuv6DZwQs9QWIjg2AvrB8kQRAT2vDjZ+CwT5nvwFWwxi/ANRAsV189KxJB7TAlWr00tmxB6SPx0WNhfQekpbCd96l4d1dx/n5vNsBRB1RF8a3ZHQs0rZmYEftQk6INSq2eM78Vpu71CScX3rHr/Gj+KyyQ62rMbyI0PSn4IGYR2LVVP1Iqn1EcTJAsQBqmNycGHnX3uAyg8cYeC0KWldtqRZNnFOJokTYNYKM8Lzsz2wadbmVk62ICRxNlR2a8/Kok1US2JEYN1z+jyKQS8EH3mQLO1C5jsu2weXB/mDu4/pBFHgcmkR/gjpwurIWGJg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: eViwGrbwCKhM4/pblmhlwgGBOb0p2KVsNt9n/9p2/jAZTqWoVF7QXI7lZnhjJs+JNnGOXDSoE5J3TkSyB+I1276Hvm8eMnXyVN7DyhxeXi25Kxc+/bxpAg1BNwMs//iPdcn7Z0PUZSfBj/u7aFuTRF+LUat3hWtL9rBv9e2fgDeme0NHODPz/rop81xBaljSZqkAzsD1IAHAC5/Xv9hE9oryBWPerwNQNx+wrulUXbbbI+le87vT4+WQKoSppyLjiXFT/nEe5VS2Uf6g3IcN3nNtzGpLhLk+MPMOeHKwPP0VIWB4kE6s3XJjXlOW5B3KdaMyLfj2Pl+nU8JVw21t11/BoPU79ALWQQEgSD6CCR09xc0BaihxmjQsr2vi4LMlPAWw5gmXuoSHXRn6VJ98LiQJMcBCwl9IR2GIcG6GaL28f7A9rAlSudomJBf8X5SJSh3gCp8uYwmoKGVsZvkgywxOYwQXqyZaGilP32AfNQqkZvdW/X5xZi5AEpdTI0CtXA5U/mLFUPszgVP77YIJZMhRtJyUR+MaRAsEDa5izkR9T6wUg86Z6Rj6iOfaKLpfH4/s5kcgpNgZlnXusuhJGrXOkH+2sq6Yq6r8xdTdIwA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b207b4fd-f9f1-418c-8ad3-08dc1cd11b28 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:21.0203 (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: fX3rrK76EzJuuRxcMie7l44mYpGyrZpA01VJx1pNIrZ8cwEL2ol+8OVuWwZovn/YI2vWzLG0B4NPFL+j/Gyt0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5815 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-ORIG-GUID: 9ZaYkbmZyi66-YbHlQBWF9FaokVvG4IP X-Proofpoint-GUID: 9ZaYkbmZyi66-YbHlQBWF9FaokVvG4IP Also update block layer request queue sysfs properties. See sbc4r22 section 6.6.4 - Block limits VPD page. Signed-off-by: John Garry --- drivers/scsi/sd.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++- drivers/scsi/sd.h | 8 ++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 0833b3e6aa6e..32dfb5327f92 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -916,6 +916,65 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) return scsi_alloc_sgtables(cmd); } +static void sd_config_atomic(struct scsi_disk *sdkp) +{ + unsigned int logical_block_size = sdkp->device->sector_size, + physical_block_size_sectors, max_atomic, unit_min, unit_max; + struct request_queue *q = sdkp->disk->queue; + + if ((!sdkp->max_atomic && !sdkp->max_atomic_with_boundary) || + sdkp->protection_type == T10_PI_TYPE2_PROTECTION) + return; + + physical_block_size_sectors = sdkp->physical_block_size / + sdkp->device->sector_size; + + unit_min = rounddown_pow_of_two(sdkp->atomic_granularity ? + sdkp->atomic_granularity : + physical_block_size_sectors); + + /* + * Only use atomic boundary when we have the odd scenario of + * sdkp->max_atomic == 0, which the spec does permit. + */ + if (sdkp->max_atomic) { + max_atomic = sdkp->max_atomic; + unit_max = rounddown_pow_of_two(sdkp->max_atomic); + sdkp->use_atomic_write_boundary = 0; + } else { + max_atomic = sdkp->max_atomic_with_boundary; + unit_max = rounddown_pow_of_two(sdkp->max_atomic_boundary); + sdkp->use_atomic_write_boundary = 1; + } + + /* + * Ensure compliance with granularity and alignment. For now, keep it + * simple and just don't support atomic writes for values mismatched + * with max_{boundary}atomic, physical block size, and + * atomic_granularity itself. + * + * We're really being distrustful by checking unit_max also... + */ + if (sdkp->atomic_granularity > 1) { + if (unit_min > 1 && unit_min % sdkp->atomic_granularity) + return; + if (unit_max > 1 && unit_max % sdkp->atomic_granularity) + return; + } + + if (sdkp->atomic_alignment > 1) { + if (unit_min > 1 && unit_min % sdkp->atomic_alignment) + return; + if (unit_max > 1 && unit_max % sdkp->atomic_alignment) + return; + } + + blk_queue_atomic_write_max_bytes(q, max_atomic * logical_block_size); + blk_queue_atomic_write_unit_min_sectors(q, unit_min); + blk_queue_atomic_write_unit_max_sectors(q, unit_max); + blk_queue_atomic_write_boundary_bytes(q, 0); +} + static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, bool unmap) { @@ -3071,7 +3130,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) sdkp->max_ws_blocks = (u32)get_unaligned_be64(&vpd->data[36]); if (!sdkp->lbpme) - goto out; + goto read_atomics; lba_count = get_unaligned_be32(&vpd->data[20]); desc_count = get_unaligned_be32(&vpd->data[24]); @@ -3102,6 +3161,14 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) else sd_config_discard(sdkp, SD_LBP_DISABLE); } +read_atomics: + sdkp->max_atomic = get_unaligned_be32(&vpd->data[44]); + sdkp->atomic_alignment = get_unaligned_be32(&vpd->data[48]); + sdkp->atomic_granularity = get_unaligned_be32(&vpd->data[52]); + sdkp->max_atomic_with_boundary = get_unaligned_be32(&vpd->data[56]); + sdkp->max_atomic_boundary = get_unaligned_be32(&vpd->data[60]); + + sd_config_atomic(sdkp); } out: diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 409dda5350d1..990188a56b51 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -121,6 +121,13 @@ struct scsi_disk { u32 max_unmap_blocks; u32 unmap_granularity; u32 unmap_alignment; + + u32 max_atomic; + u32 atomic_alignment; + u32 atomic_granularity; + u32 max_atomic_with_boundary; + u32 max_atomic_boundary; + u32 index; unsigned int physical_block_size; unsigned int max_medium_access_timeouts; @@ -151,6 +158,7 @@ struct scsi_disk { unsigned urswrz : 1; unsigned security : 1; unsigned ignore_medium_access_errors : 1; + unsigned use_atomic_write_boundary : 1; }; #define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev) From patchwork Wed Jan 24 11:38:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528994 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 07E9C4F88F; Wed, 24 Jan 2024 11:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096507; cv=fail; b=htOsmU3UYu3fjr5T9/qQsPX/fu/f6xxhCEIfumFJGQsQO4yyNYT7ZUV8ef3i1gQ84TMHlFOFROBtnbrarFoDDCDHbx3CvxAxrwYNBfGFUOfRbkRRgxfA8D7Ia2Nu/itV4YhF0RiRks36T0K+OrAWYVQPKB80fg4ocFSqVR0Fk3U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096507; c=relaxed/simple; bh=GC6ylPX4dQI/1NB88ih3Z9I/YX5vcquE15oYpkKgq9s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=KYHjXyHAAigAPpAGDYD+ROGK4PHAY+M61bY8IOtYsrhNsgWOwCL1nHPV64H+bfib3l7Z/3ZWTNWfMTkamxz5VYAV1HxmWgm1lfbITOrpxhM4iH+WU1++iB4p+czrRaQwfxxtp3bP8STPfJAJpB2977tc/Bbixmiun3NO2WnWANQ= 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=ihO35mAo; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=cCYHxPJY; 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="ihO35mAo"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="cCYHxPJY" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40OAwiWF002342; Wed, 24 Jan 2024 11:39:25 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=Wvz7ujkQkNFdmcLVymGBe/+aemLauhqF1vKIiLipy0E=; b=ihO35mAoy100pBSCqC7+u4E0Nwof6+5ROP89eNJ+cPTPm+yPo1A6gqrhL0Nh2rCOtE/t 3FujmT0GMPtxBl98Ggw/MyXnoPhAQduTS+1naZiOrvFyFZEyq6UHXGtr4sNT/uGF+ssg LjzQNgIOqIjUDyKM3MO/DKSoiwNDd+J+AOjJzx8kRKC+Tp5AryA+jx0S69T1aw6GNakQ pzzz07aOoNd5zz3plDzguAXfhweetEAAc8mdcAx0Qk2OYYLZD9OnEFbBmuM1a5PDn6BJ 4Dy+hMyvWvCDpv+MgUKQyaxrHDtiYCS8rcJ2Jk7426SWKnzA8rfSUAGit6xERMEnhLVO yw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7n8239y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:25 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40OBKcRr040865; Wed, 24 Jan 2024 11:39:24 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vs316wnyg-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WgTQp/l/TgHP9awSFAiWwlNpboz5y7DBV7KGL0LhHCNw+g7aFSU0n/I0yvJid0JfY0QflYam8+4IKsM5saKWxFRHeh90Z0CL8ijOZWsRR8GFwOyCIni2MUjjrflNO7HiJEtNJEJz5K4OLu6uY6rDsdFFLun2hHzhFCrFKalRRSv1WI4X8KREPC2+YLzsXXj6l+ADa2heSDHnIQ+ZbeC5pEJm7KbuZqDQsl2yaKBNaNl+BE7gnZ5jE6+RpYhcQept9i4eSm90VKm76H8R8OBjg5luOx0JBQlD5HtMXAmpBBz1NUMyFisDpt3JmnznHZp8kJgt1fv72n0T51+dRJ0+lw== 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=Wvz7ujkQkNFdmcLVymGBe/+aemLauhqF1vKIiLipy0E=; b=oHVKpqE4iGzgHWVzwTQrFNVDQUyk6avjd3/TS5iKw8n0G8NBD0Z5K4IdJbl1wf7ujARUok6pb9Do6oxLhFQ62Ec5X2S0fJAYjqom3IZLUrNqeBvHZVFmaIxebRvmXse8vW/3ynZ9NhFlpPjr+ZjYCtbax0HNY6VEkxxkD+U3mxdwGarxGMEqh6yZlS9LzzbbiQAV/vIk5URcnW+kB7I8HEIgeCeHPkgN/kA46rplGwnYRFA/hesLpp056/519OF7wwdz2lyJJa3CSK3oqj2y3JVLaUuCHLgPodB/YMlnhmY8ZWosfpyGT3gpG4wYXnu29+/AvjFEwOYW51Dao0/ThQ== 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=Wvz7ujkQkNFdmcLVymGBe/+aemLauhqF1vKIiLipy0E=; b=cCYHxPJYsZaybg8RncShHyilAXlOo2jfrGeVTdvsUFCclw8cQ4dbeh+pkKxy9dkBZgrFPJzSXOcLwmEypIeld2FJPWQjALjzy+SkRFyLqI8cUwhf3I7e+tqK8/M2ZIde0c6CG7vpkRp5p/6v1zr7HAlM82Du7L8AgLcMxHnWLHU= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB5815.namprd10.prod.outlook.com (2603:10b6:510:126::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:22 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:21 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 12/15] scsi: sd: Add WRITE_ATOMIC_16 support Date: Wed, 24 Jan 2024 11:38:38 +0000 Message-Id: <20240124113841.31824-13-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAPR03CA0123.namprd03.prod.outlook.com (2603:10b6:208:32e::8) 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_|PH7PR10MB5815:EE_ X-MS-Office365-Filtering-Correlation-Id: d2accf8b-1e09-45c7-33d5-08dc1cd11ba7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rMJRUXcR/h9nze3yvgcNlO+7y7w7YWCREuNr+erPeM78R3u82kKH5bMnyW6M+4JBmCJ2B2wFFFLRr8wR6M7yErXNeU9j7u6z7aueOAIFrYf1KWoMf8A93tKxI8JxtTgWj2PNL3Nzfyssjmsa+XD16TgY9GoUDmNjZDRvN1bGakTUaAU7voEeJqhwh4Jtk6wvjR+FtEAsWKv+MeLV+ixvtmLr61u55+rOV87DGtDd+BstM2HN/BkLoTFpjt8DUk1EaGRKsfvPZ19VCb23OMLVnogcF8fEY/P8Xl6Wamayu24ozy3o1XoLTxgolfGoSJByHd5GCQtOBKx2Q3QdIBOzPYW1m6RvVVyIOvxwcLX6dCLRHOAICXKiPPB/CFp5Tv7Ta1e7zGXdeMuvyYv06QBA+qCevNPTrZnLZSIG9LZTpFICbnoiag7ovYCEEiJsMbFmNWvMNWiEuBLv8ruzVOt2JeMYTs5JityiOUlNmOUReX4DembzkRRI2vUAQQsgY17ECXWdzXjSP053kQHe3C4k1Joj0zG2MyWA4RzVy5+8z+ArFlSbYmAILgI77zAQxYInttRYDOVtRMAraYMVU2/S898m2dpZsDulQ/0yYnFC3jA= 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)(376002)(396003)(136003)(346002)(366004)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(83380400001)(41300700001)(1076003)(6512007)(107886003)(26005)(2616005)(38100700002)(6506007)(8676002)(4326008)(8936002)(5660300002)(7416002)(2906002)(6486002)(478600001)(66476007)(66556008)(6666004)(66946007)(316002)(921011)(36756003)(86362001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pNBIbsfEI9nXd6uZi2dS+PdSDXpopxZvGuYyRPEkTkxcGeM27XFhNx3DRKZVSKPL6Y/A5MFytowBMx6YjjQZII0kLdqFGA0k4ETC8MRYYI9rWFVp8LqBBG+rTdSVA4WCF9sWPOSe31vRFaGiKt9pLS3yKO8z/V3hdvjiSQs+4Yrkn65dilVvQysRl5sFbjA6EhDi0NE7NrLARvH7Gs+YurH0XhQaa/PaVYV8NP6/t6ix/T/p9oQlg8qrUhnvcv+v9ZAg9tdIs4Vi3JpNC5n2IEpOhWnJchQjDAA8/UAR2vaZIez0lSJR8tBKeIDD1CrEPCELEPQL2ssYAWJST/Vy10+iPeQldcKExFgaShr5IbWqQZ8yjqxvH4sp+aH4yWoDstf3Vd9iFTBygiZHAO9hf/CL6oeW8430BgwdLzJIdQ8PksxkHihnsp1s7wxxNYg1tdpJm72NI+kgV5P7RB2JJBFHIhzliOLLzJ4pwKo+2HUyzdtl48dEq8VVKimaXywHp7MwHK0nz5576lL5t7GFQG7/FGxp7ZkI476msPDcIFB6j1stcgjPMaPlhaATPe2AmF0w3FBAfN/gfOPO/zdiWKSneNQLthYNk+rNQBaJYAGrE5rSU0qDJwqccOm/bedEwdczWqwJri4MrQmo3k/8UxowgTvA4CLCOxNslHIi92pS1TC7tDzcuJuMv9tTvw80ecGzT61CBMIg7Is315jJorerp9IqexP9eAsjuIahTRQGXtz5Zg3D2TURGNCwN6vCdzBRr5VDL9Cr6XJ52qGjrXyorvi1Bf//wvuTQFX+NgaIoEg3UDcpYvpUVjbHRTI102je+EBvhQHyGaxoVR2Jsw4q+Qs8eFCYcDAY835rkaCzEQueLQBkdpIo77XCaXVGGLrTxhwQ/rtpwC9R8/Nd1IvyuJgF8azSiI9bv2xuhnVuTgN3u71AP3ArZiEqmmRZuNkuz3YNTimIfpPLxEOxsCOSUMqogEr13JRCEKosEfV17zevQx9NOt7rzgsg3v7e6b4u/d1O6K/0iWOrGxPTZDSJQupURw5c6p0aoLefDKvY8c+FEKPux/YeOLsu7H1DEAh3o300yuZGc4k0tNMTQL9sfsiFMp8oKB6OmpZXS7TA+iYus0M8+UJQg4eT2uk/GpZ/5LOjGzaeq3iGW0mCQZJfml5TpEwwTYRVZdO64M4vLFK3ao4VG5VkRAdX4Qk5zs2Jt3MoZYFm9qM70WHd6KVNdNUn+KVJi7ZsXT/7oXP2b/mq9tJbIxtjCmPfv+NsitbCxcRFF7bmdo0PTDisN6IOECz8smq84vl+0hJzsmBelfcdFMmXo3yVgLApT4DV6MqHvY5pEFabHSlbSMnBlcwBDFdDR2CfYV3DK3Mnwp7lL0OKMqys1Sl4P8HnADxzLH2epGb1eYd/jQhCQp/cUGdbPKURtCSmTWw8Y2VMU1PCUIEGmZjNV567T1xGi8AhWEksz+BapB/VwyZ+1lfa1gb+lhCnJsKLepCBjHNp3lDKwITSRfvfMjHoLfOkThl8vst1n/Pp4I++KkBa85rWxruT/AWjuzzY0pgBEqmniAUGYY/Fe2xwnEfN/f/DAdl8PF9+aYOZNydWi0Aeaw1Iuw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 5ohyIq8jwxFaByjGnxR825DRm1yupSzCiJ0sn9hvv/vdPPB3ABr5q9fQj6z4/H9geXIOb8w07XEm0CPvfnNYasBoeanR1hhobtdsSil3wtuukBlswLRXpxFCwAC3Hwl2z0jEjy3XpCc4u3gw7hcG2QCZFgFltUp2TkCptJAkFr/TC9cfDkD3HDIe+f2XwEktJlFmmVWxxqr66aCjq0Ee1Hq8xQMVT2zn+V323fsa+8SMTWIG6SWhobvBocX393v1ct+HQoYaa35Xmcs2prkvmiVrkqNEDRB22CzOHy7g498KHt+41rHlLfmESwi4PAjmt3Em89olePzRCy7D5N1mJsfIGjfKzSJSVT1+Jy/jKNkKlik3lbq/uLXe19I2ZbtCPZCWn0D4OsLZ1LPj9vJT6biC21PqixOuzdj3+3ZF6jVEo4B/AyCUjjMcCo8Gu3yLuBWVdhQHz9nEaTFch3P895DwUHfNC++OG/wmbBJdcwYvOF0LLYHGnm5OYbtarL9wWBGGmbeCCt9EOLIxuIq9biuR8Qk/3Rd3JrDXqqAZyw8PnRWEKdfqVsxCQQzojNKiQlitLXH0gonVmtIra4o3J3X/hENKAFfGxdtuJakNQs8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2accf8b-1e09-45c7-33d5-08dc1cd11ba7 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:21.8287 (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: h/eau/8LV6DUChFAYobMju62RCPcdXPJXWZy7vmjtBYM97MIOtp2Ev+uVdeE/LRrTiylz8b6JrzQ0Hom1v1BVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5815 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: q9TkkVJMWBTu0z72auISEKWcTLU1YY-P X-Proofpoint-ORIG-GUID: q9TkkVJMWBTu0z72auISEKWcTLU1YY-P Add function sd_setup_atomic_cmnd() to setup an WRITE_ATOMIC_16 CDB for when REQ_ATOMIC flag is set for the request. Also add trace info. Signed-off-by: John Garry --- drivers/scsi/scsi_trace.c | 22 ++++++++++++++++++++++ drivers/scsi/sd.c | 24 ++++++++++++++++++++++++ include/scsi/scsi_proto.h | 1 + include/trace/events/scsi.h | 1 + 4 files changed, 48 insertions(+) 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 32dfb5327f92..7df05d796387 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1240,6 +1240,26 @@ static int sd_cdl_dld(struct scsi_disk *sdkp, struct scsi_cmnd *scmd) return (hint - IOPRIO_HINT_DEV_DURATION_LIMIT_1) + 1; } +static blk_status_t sd_setup_atomic_cmnd(struct scsi_cmnd *cmd, + sector_t lba, unsigned int nr_blocks, + bool boundary, unsigned char flags) +{ + cmd->cmd_len = 16; + cmd->cmnd[0] = WRITE_ATOMIC_16; + cmd->cmnd[1] = flags; + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[12]); + if (boundary) + put_unaligned_be16(nr_blocks, &cmd->cmnd[10]); + else + put_unaligned_be16(0, &cmd->cmnd[10]); + put_unaligned_be16(nr_blocks, &cmd->cmnd[12]); + cmd->cmnd[14] = 0; + cmd->cmnd[15] = 0; + + return BLK_STS_OK; +} + static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) { struct request *rq = scsi_cmd_to_rq(cmd); @@ -1311,6 +1331,10 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) { ret = sd_setup_rw32_cmnd(cmd, write, lba, nr_blocks, protect | fua, dld); + } else if (rq->cmd_flags & REQ_ATOMIC && write) { + ret = sd_setup_atomic_cmnd(cmd, lba, nr_blocks, + sdkp->use_atomic_write_boundary, + protect | fua); } else if (sdp->use_16_for_rw || (nr_blocks > 0xffff)) { ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks, protect | fua, dld); diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 07d65c1f59db..833de67305b5 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -119,6 +119,7 @@ #define WRITE_SAME_16 0x93 #define ZBC_OUT 0x94 #define ZBC_IN 0x95 +#define WRITE_ATOMIC_16 0x9c #define SERVICE_ACTION_BIDIRECTIONAL 0x9d #define SERVICE_ACTION_IN_16 0x9e #define SERVICE_ACTION_OUT_16 0x9f diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h index 8e2d9b1b0e77..05f1945ed204 100644 --- a/include/trace/events/scsi.h +++ b/include/trace/events/scsi.h @@ -102,6 +102,7 @@ scsi_opcode_name(WRITE_32), \ scsi_opcode_name(WRITE_SAME_32), \ scsi_opcode_name(ATA_16), \ + scsi_opcode_name(WRITE_ATOMIC_16), \ scsi_opcode_name(ATA_12)) #define scsi_hostbyte_name(result) { result, #result } From patchwork Wed Jan 24 11:38:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528990 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 2E07C58AD6; Wed, 24 Jan 2024 11:39:51 +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=1706096393; cv=fail; b=B+xqUmX1knbycFt17AYsSaoTdw2w5o0vXMYbEcJr9DyNPDWZm7GAJZgApjS4geAkXXeQ4Vs/jFwL+JW0cFRl2A1rPg4P6lRTzzT+LTaeV5zuPgYdwkuHk1utnDmDNU1Iq89KsTSX58yUJKZRsnXxnRDtUVKVQft9whtw6XmlT7g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096393; c=relaxed/simple; bh=QORm1MehXryOGbP8qbyrOoSGYFYh0SmDv8PwUGh5RxM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=C87P7fxEA+JGu3YqQhMI4mkdJPGLA5JRH3lFM7+WkKYkrSfiFSJ+oBH8pn/QIHZ0vUjZ1AUwOm13k7MHNC2p0npNhgEm/V/onGwb5gSaOaLL5zS8csG5MXAwqD+BQi1n/bWWyQntKrg4nl8iOcGaywqPCFIdk2FLfC7qnLRzDio= 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=JX3UDb58; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=AcPgOF+J; 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="JX3UDb58"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="AcPgOF+J" 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 40OAxPc9012850; Wed, 24 Jan 2024 11: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=IqqqxqpCVTWQua3wiLwY354Qu+LLx+CD9DlauyVvVd4=; b=JX3UDb58eB3eOL5HGbELnAijB24nFiuSWauTttz5VZWhpjcf+U4YXGGDEg9oP9zU6fl1 FItXKYtJfD0q23xBfxiFQgC0PJ0481Sfxhe8xII64k42Rk2EqTStwDJJsBtEjIlVe602 rCicB+R5rKJ+l8/rrAHpOJKPcLRFkpR7BJpcKM5dvGsni6UPqiWzbzyZKkzqROi+gmQC 0VayUKkdtVT/chbJYLwJl1RHn9FOHu8ACCLDL1CRQ4kH9arZwzMMY1lIc6oPIvWy2COQ Q4AWL4O4QWPAA34c80DPOpJFXqv0RNdaaSpgp4m8/82bIrtRXHTE4iKu+CuMdE5+31/R 4g== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7ac22hj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:27 +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 40OBPAN2006158; Wed, 24 Jan 2024 11:39:26 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 3vs32setbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kkq1ntGe6zBsdAz7KsB0ezCuYi3ltrv2W1Wj8Qgi+iSCyVVcCMtqeHB4lfnPZZ5sicwHyk6CAJlXjSpm+117dDDjbIUejegvZzxeAvQfwQVOXIhyXZwhk4826eGN8I7OBz4+MMy74DsIpIHQCSKSwE2+vAIJ39tEbu25pWLJpMjWo5LGuW+/gQjB3rFzCzRuxn4H7BkO0gKNIHWOJENk/XiTMwo040988Xz79aBNEk3LEPZ/kAEG4BCIoPYIVGIGgESeC04nOYN8Wg3KpTdVPExGktTwKnIzGtbN0PWzCS8X45ozL7FQan/1gqbqRvRWPI8EEHkKCKN0ATvCBeRr3A== 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=IqqqxqpCVTWQua3wiLwY354Qu+LLx+CD9DlauyVvVd4=; b=QeBlAR9m68X0vUx7Yw/VTjprVFB2vDP9lSHCRQq9CQsa0kOZ8Fc1oDygpFpG7PW5hTIElr2U22q4c8lB2v53QYEJ8qZEzAlvBWmYe6F4TWVOG2BdE3mqPJIfZ/TP+NlOPf5JpGcH7snIM/KtEOi1OdsJtjqZsTn/ZGlTfNFfYNzFgmdqaSgpAdefVXCG46TO8HLH1mtlKeRnlf6Aozw2WyoqqJD7OyPyvDcp+2QJ+YcOgxWLsoHbL37GNJlIVucD2pt2uNwxfegH+tEqDofa043WEd1fl30y6GlqkwyaEjczB4/x9ZxJB2w9KbW4gmhYp2diwxbVhXUxDspdbz//hA== 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=IqqqxqpCVTWQua3wiLwY354Qu+LLx+CD9DlauyVvVd4=; b=AcPgOF+JF/SDoYr+BPpc0Kp3yiywtza//LeoIu1AgSgyIxryr9r7eeMXIQlIM6fhE6gsSprOMq9JOYBR7U2PAXoojGkntjwZ6n4CEW+3oDsKeVZK3EjstyA3Sz3MY9vxe14ZYBgKeR+Rb5AdY/0AcWickq6N4ivSBYsUD9B9CFo= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB5815.namprd10.prod.outlook.com (2603:10b6:510:126::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:23 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:22 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, John Garry Subject: [PATCH v3 13/15] scsi: scsi_debug: Atomic write support Date: Wed, 24 Jan 2024 11:38:39 +0000 Message-Id: <20240124113841.31824-14-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAP220CA0004.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::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_|PH7PR10MB5815:EE_ X-MS-Office365-Filtering-Correlation-Id: 64dc679d-60db-4298-3b48-08dc1cd11c4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cq1eYxKrxnsKMUCVu2B/JTrF0RH0n0cLO6t+euHvoqU3xIYl8TNJpjAVGssjT+svOUi5CpncphefE5vEEkLqIrWQ/WT1Pn8WdJ65SYJvd8oNNquAQTZJNh6AksFjTqHMTIWgDl+ZysDy0nBdOWHR8AVuKHBS4R1NZ49LD/TH23iHGb7WCk/ZtnH86gu/ZDUJP5nZdhbgDgRLPfeW/u99bMwlZS28yoXYGdISAXj11BfP9329YdsvcsgvCxUQ4VsI711eASxglLJAE/hdlDcD+1iCF9/0QCKngihfHa8vlRlkJ1+YuTpY/YdG+GXHGapnRh0aaHf80qNXJLbYJbF/GQlYTDBOp78UUP4s+8IcfinBactOeTmc2TGwadjrpm1c8spTbLK8gn6nX96z6Bb8U7ndihQMxbtnVs1Tz7s6xYzpW7I9okA8nQCjg33BIfabYiFOVao1tfSSZWkne0NIZAOY7FjaRPIgSuN4XoyGpMosTBdr32Q7YcPDYYcz8pCEtvvgt4oAttFBfuXcWr/abTaf+KRWC1dwBw+9roLdE3CApxg5/Q2TyOqlcWoFN4OKVnasUWJtN8GOS00PMWuYxgweENmZJlJMIU8Ay9GCZa9DnI4Qki5sHKZlMbRtyaZm 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)(376002)(396003)(136003)(346002)(366004)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(83380400001)(41300700001)(1076003)(6512007)(107886003)(26005)(2616005)(38100700002)(6506007)(8676002)(4326008)(8936002)(5660300002)(7416002)(2906002)(30864003)(6486002)(478600001)(66476007)(66556008)(6666004)(66946007)(316002)(921011)(36756003)(86362001)(103116003)(357404004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: M7uLADAnyCsUo7mysex4yPGgC/rJWome/MZHLIvhG1frK9HtiOI+dvvr4Da/Lz0kx4NaCQJCXMkXeJl+Zw4Qv7B9c/zDygMnvOdQTCjRtukBHzikPv8XN2ta8UOIkvXzmyMKNTbDgLHRu/dTvx3paIflV9db0oXTUfke2HZhQpeSqMCpeFWqvIoc09PFOek+Vvm2RxMCfhYiKysN9E+RPI7vXmqm+pvW8dnA+yOBi+/0fUPEI8NvGvHRUN3vKqs16k/RodH9NUZcceO0z16KCkvBjpZWWRuURjkfLNgxUgKIOFywDQ7j3h+A6p5hdT5DvEkZY+/eEpSKOhZhRbrAouik/l1Oz/Pj8/EWjLk0Rg+8LvnyEzjM++HaQqgfHRKhpN1X51KKtwLaz6owVYxRsB/zOF5emcmKdb4fdcxkMF2SWA7nfQh5mZWUag8XZvKAFbAizyCiBkIIkh6cm8m7UJAD2CWpnoA/y4YtXxY/NmtvyzVqSA58HVW3Q3rMNQQdkp2d9u0AFleqPIN4AdUQjGCgSCRj6gMDZYGKTdmotEx2aeFz6sw20AwjbS8y2C6wy1sPh4BR8K6Pf2/sd3rdvSPgYLBAusQMJyVOTP5rparuw2p0lPdml3tey4ebzI5CJb+AZ4UktP6vDyQ6DbfQnllzERSTdgwalWXH+m7/TOKKzHFdOcj4qDgq8WVJMu+maDX6E8+/gMOE7p0bIPAFyA9K92la8oza6UGKR4lq7L8EYNu3/wSG79M+7U5aq0WpnVu4C3KN6fPcxEOZ4UnknBtF4fhI+FeXP4FVhHuYhBQFkJKBd91ez+12l/AAvInZGol3q/RvwM9dWznLrsRs7Wtk3KmYRI8dHveLtUI1OiFBjNqjrasxVLg+8Zbug936B+x9OGnU+kCBW+UOTI6ChfIs4ZyIE68QmvXYA6Em/BIP9pWi0Sp9ae4Gvb9UF0xB6pgHLaUBdKxtuZIHCA0M9VwNJupp3BDDukeryDgijSiwDJIplqTNwl3nR7kw0XKsR+cO0rer+MAOvozPhC1qD2c5xl5nOi5XsGP3IZrV74FXqRXw0jr9VZjDYNTVTz9U+oMuYorBbtRkqqHQtVBKPBqY70ciB9fiuXYC/ZRamq5yImyCUY7PMmML0YSAY7C2wsUwxsC9JqcwcvlHIps45fJ3z3cbpOyR2SFWG20hln6uSekABcGbYzy7PbfMOsAXkBYeX3WMFtO+uZpajkOtfGfHqfFJ7bSIT16Ol4NKqfhMYuuzQzY9a9f3cd7m3MpIZI9T7U4wSaVZR1d8pkiVjnoI4pHOavQc5Yy9wCV+4IFCXdN8ByBYyJ/TKRuM5vGxJuDgilqzXvS2MHHl7MPV+iEregj0IvIMl6ndtAH00SZPAnYfy4FKA7vlcsNH4/bl6a7/mg58TwLJeS48AVABn1cyMge8h6bhvTJrfotjB1NMj3zBTIMl8y8UEfsnysVKTd40bZ7KLkBn9BBeER58KHpsp7P0BethAkO+cn5cxNbjWwaEW0q9Dg9zJv27QN7CNbP1+YBYk+R/Q3e9TNiBzH0m6pKHXc7ppeqpOaysQVTAROjQHBOXrDl0qpT17E091nentGqeXYL2SwPbWO27mg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: DEYmJtWGbk/k97CQhEESJLeSfdhOdoikML+IrY1KTa+J3kBA2I61x/i0d4NC7YOMD9mM6921ig7TJOclgj21pdAnEPHyUYZQpqVNDNU2FcIwD0ucYCzbLroskG6ufQTWgLgQcmiNH53s1uF0Dkh9x6x82+tnN0qX3xxg+0+Na+PTJeH6aWlhzblzCWoCKxvVbXCLgFMTZmo+wvBXye7oBMy84vMHiaPn62QbclG6owaHyCkEnQmJT8UkRTxMzThxmxOVk9uDZC3/Y3oSsztEOgq1UNQL5Wyojv1uD9xoqJaxDbZ7mts6OLve+f0q686ZwjpBFoZtFO8+dgGN6LKUCOB2vqhX1wiEukMDerEd+IMUjDzI5oUXxh/ar3pJLKCM+rttEmM+wtClzt/HkqV0reziLJnpm0lSHG8xZDqJGWZJ6UUxwdnZKAibpbK8TNRY0LX60KZ7ya0fHP7zQbJQx5fMf1i6v6paYPkAYx1FV/jOIUZU0wksji/HofDaOr4HuUXlZ2Y6A1A0y9dcSqNoPO9Y/y9VPz4qIAhVCbvXYWRrGlZz+B8TlHsJ+FdGBIYioGFT9c3iI6unaTsQcBOiXTuyyewfdT6yvfii41c0xkk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64dc679d-60db-4298-3b48-08dc1cd11c4d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:22.9385 (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: MxU1GjKPQqPC01/flFW5KIGQdPt7e6B9MhKqIE52GyeBjGjiWTmSs8s7daIBpzLxU8VTAYa+/gaKTU76eR+Rew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5815 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: nM3kf6gk0-pSswAtKlW0ph5dJGecbu6F X-Proofpoint-ORIG-GUID: nM3kf6gk0-pSswAtKlW0ph5dJGecbu6F 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 | 589 +++++++++++++++++++++++++++++--------- 1 file changed, 456 insertions(+), 133 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 9070c0dc05ef..9568bcbf0821 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -68,6 +68,8 @@ static const char *sdebug_version_date = "20210520"; /* Additional Sense Code (ASC) */ #define NO_ADDITIONAL_SENSE 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASC 0x0 +#define OVERLAP_ATOMIC_COMMAND_ASCQ 0x23 #define LOGICAL_UNIT_NOT_READY 0x4 #define LOGICAL_UNIT_COMMUNICATION_FAILURE 0x8 #define UNRECOVERED_READ_ERR 0x11 @@ -102,6 +104,7 @@ static const char *sdebug_version_date = "20210520"; #define READ_BOUNDARY_ASCQ 0x7 #define ATTEMPT_ACCESS_GAP 0x9 #define INSUFF_ZONE_ASCQ 0xe +/* see drivers/scsi/sense_codes.h */ /* Additional Sense Code Qualifier (ASCQ) */ #define ACK_NAK_TO 0x3 @@ -151,6 +154,12 @@ static const char *sdebug_version_date = "20210520"; #define DEF_VIRTUAL_GB 0 #define DEF_VPD_USE_HOSTNO 1 #define DEF_WRITESAME_LENGTH 0xFFFF +#define DEF_ATOMIC_WR 0 +#define DEF_ATOMIC_WR_MAX_LENGTH 8192 +#define DEF_ATOMIC_WR_ALIGN 2 +#define DEF_ATOMIC_WR_GRAN 2 +#define DEF_ATOMIC_WR_MAX_LENGTH_BNDRY (DEF_ATOMIC_WR_MAX_LENGTH) +#define DEF_ATOMIC_WR_MAX_BNDRY 128 #define DEF_STRICT 0 #define DEF_STATISTICS false #define DEF_SUBMIT_QUEUES 1 @@ -373,7 +382,9 @@ struct sdebug_host_info { /* There is an xarray of pointers to this struct's objects, one per host */ struct sdeb_store_info { - rwlock_t macc_lck; /* for atomic media access on this store */ + rwlock_t macc_data_lck; /* for media data access on this store */ + rwlock_t macc_meta_lck; /* for atomic media meta access on this store */ + rwlock_t macc_sector_lck; /* per-sector media data access on this store */ u8 *storep; /* user data storage (ram) */ struct t10_pi_tuple *dif_storep; /* protection info */ void *map_storep; /* provisioning map */ @@ -397,12 +408,20 @@ struct sdebug_defer { enum sdeb_defer_type defer_t; }; +struct sdebug_device_access_info { + bool atomic_write; + u64 lba; + u32 num; + struct scsi_cmnd *self; +}; + struct sdebug_queued_cmd { /* corresponding bit set in in_use_bm[] in owning struct sdebug_queue * instance indicates this slot is in use. */ struct sdebug_defer sd_dp; struct scsi_cmnd *scmd; + struct sdebug_device_access_info *i; }; struct sdebug_scsi_cmd { @@ -462,7 +481,8 @@ enum sdeb_opcode_index { SDEB_I_PRE_FETCH = 29, /* 10, 16 */ SDEB_I_ZONE_OUT = 30, /* 0x94+SA; includes no data xfer */ SDEB_I_ZONE_IN = 31, /* 0x95+SA; all have data-in */ - SDEB_I_LAST_ELEM_P1 = 32, /* keep this last (previous + 1) */ + SDEB_I_ATOMIC_WRITE_16 = 32, + SDEB_I_LAST_ELEM_P1 = 33, /* keep this last (previous + 1) */ }; @@ -496,7 +516,8 @@ static const unsigned char opcode_ind_arr[256] = { 0, 0, 0, SDEB_I_VERIFY, SDEB_I_PRE_FETCH, SDEB_I_SYNC_CACHE, 0, SDEB_I_WRITE_SAME, SDEB_I_ZONE_OUT, SDEB_I_ZONE_IN, 0, 0, - 0, 0, 0, 0, 0, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, + 0, 0, 0, 0, + SDEB_I_ATOMIC_WRITE_16, 0, SDEB_I_SERV_ACT_IN_16, SDEB_I_SERV_ACT_OUT_16, /* 0xa0; 0xa0->0xbf: 12 byte cdbs */ SDEB_I_REPORT_LUNS, SDEB_I_ATA_PT, 0, SDEB_I_MAINT_IN, SDEB_I_MAINT_OUT, 0, 0, 0, @@ -544,6 +565,7 @@ static int resp_write_buffer(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_sync_cache(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_pre_fetch(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_report_zones(struct scsi_cmnd *, struct sdebug_dev_info *); +static int resp_atomic_write(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_open_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_close_zone(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_finish_zone(struct scsi_cmnd *, struct sdebug_dev_info *); @@ -782,6 +804,11 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEM_P1 + 1] = { resp_report_zones, zone_in_iarr, /* ZONE_IN(16), REPORT ZONES) */ {16, 0x0 /* SA */, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xc7} }, +/* 31 */ + {0, 0x0, 0x0, F_D_OUT | FF_MEDIA_IO, + resp_atomic_write, NULL, /* ATOMIC WRITE 16 */ + {16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} }, /* sentinel */ {0xff, 0, 0, 0, NULL, NULL, /* terminating element */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, @@ -829,6 +856,13 @@ static unsigned int sdebug_unmap_granularity = DEF_UNMAP_GRANULARITY; static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC; static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH; +static unsigned int sdebug_atomic_wr = DEF_ATOMIC_WR; +static unsigned int sdebug_atomic_wr_max_length = DEF_ATOMIC_WR_MAX_LENGTH; +static unsigned int sdebug_atomic_wr_align = DEF_ATOMIC_WR_ALIGN; +static unsigned int sdebug_atomic_wr_gran = DEF_ATOMIC_WR_GRAN; +static unsigned int sdebug_atomic_wr_max_length_bndry = + DEF_ATOMIC_WR_MAX_LENGTH_BNDRY; +static unsigned int sdebug_atomic_wr_max_bndry = DEF_ATOMIC_WR_MAX_BNDRY; static int sdebug_uuid_ctl = DEF_UUID_CTL; static bool sdebug_random = DEF_RANDOM; static bool sdebug_per_host_store = DEF_PER_HOST_STORE; @@ -1180,6 +1214,11 @@ static inline bool scsi_debug_lbp(void) (sdebug_lbpu || sdebug_lbpws || sdebug_lbpws10); } +static inline bool scsi_debug_atomic_write(void) +{ + return 0 == sdebug_fake_rw && sdebug_atomic_wr; +} + static void *lba2fake_store(struct sdeb_store_info *sip, unsigned long long lba) { @@ -1807,6 +1846,14 @@ static int inquiry_vpd_b0(unsigned char *arr) /* Maximum WRITE SAME Length */ put_unaligned_be64(sdebug_write_same_length, &arr[32]); + if (sdebug_atomic_wr) { + put_unaligned_be32(sdebug_atomic_wr_max_length, &arr[40]); + put_unaligned_be32(sdebug_atomic_wr_align, &arr[44]); + put_unaligned_be32(sdebug_atomic_wr_gran, &arr[48]); + put_unaligned_be32(sdebug_atomic_wr_max_length_bndry, &arr[52]); + put_unaligned_be32(sdebug_atomic_wr_max_bndry, &arr[56]); + } + return 0x3c; /* Mandatory page length for Logical Block Provisioning */ } @@ -3304,15 +3351,239 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip, return xa_load(per_store_ap, devip->sdbg_host->si_idx); } + +static inline void +sdeb_read_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + read_lock(lock); +} + +static inline void +sdeb_read_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + read_unlock(lock); +} + +static inline void +sdeb_write_lock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __acquire(lock); + else + write_lock(lock); +} + +static inline void +sdeb_write_unlock(rwlock_t *lock) +{ + if (sdebug_no_rwlock) + __release(lock); + else + write_unlock(lock); +} + +static inline void +sdeb_data_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_data_lck); +} + +static inline void +sdeb_data_sector_read_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_read_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_read_unlock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_lock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_lock(&sip->macc_sector_lck); +} + +static inline void +sdeb_data_sector_write_unlock(struct sdeb_store_info *sip) +{ + BUG_ON(!sip); + + sdeb_write_unlock(&sip->macc_sector_lck); +} + +/* + * Atomic locking: + * We simplify the atomic model to allow only 1x atomic write and many non- + * atomic reads or writes for all LBAs. + + * A RW lock has a similar bahaviour: + * Only 1x writer and many readers. + + * So use a RW lock for per-device read and write locking: + * An atomic access grabs the lock as a writer and non-atomic grabs the lock + * as a reader. + */ + +static inline void +sdeb_data_lock(struct sdeb_store_info *sip, bool atomic_write) +{ + if (atomic_write) + sdeb_data_write_lock(sip); + else + sdeb_data_read_lock(sip); +} + +static inline void +sdeb_data_unlock(struct sdeb_store_info *sip, bool atomic_write) +{ + if (atomic_write) + sdeb_data_write_unlock(sip); + else + sdeb_data_read_unlock(sip); +} + +/* Allow many reads but only 1x write per sector */ +static inline void +sdeb_data_sector_lock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_lock(sip); + else + sdeb_data_sector_read_lock(sip); +} + +static inline void +sdeb_data_sector_unlock(struct sdeb_store_info *sip, bool do_write) +{ + if (do_write) + sdeb_data_sector_write_unlock(sip); + else + sdeb_data_sector_read_unlock(sip); +} + +static inline void +sdeb_meta_read_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + read_lock(&sip->macc_meta_lck); + else + read_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_read_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + read_unlock(&sip->macc_meta_lck); + else + read_unlock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_lock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_meta_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + write_lock(&sip->macc_meta_lck); + else + write_lock(&sdeb_fake_rw_lck); + } +} + +static inline void +sdeb_meta_write_unlock(struct sdeb_store_info *sip) +{ + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_meta_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + write_unlock(&sip->macc_meta_lck); + else + write_unlock(&sdeb_fake_rw_lck); + } +} + /* Returns number of bytes copied or -1 if error. */ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, - u32 sg_skip, u64 lba, u32 num, bool do_write) + u32 sg_skip, u64 lba, u32 num, bool do_write, + bool atomic_write) { int ret; - u64 block, rest = 0; + u64 block; enum dma_data_direction dir; struct scsi_data_buffer *sdb = &scp->sdb; u8 *fsp; + int i; + + /* + * Even though reads are inherently atomic (in this driver), we expect + * the atomic flag only for writes. + */ + if (!do_write && atomic_write) + return -1; if (do_write) { dir = DMA_TO_DEVICE; @@ -3328,21 +3599,26 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, fsp = sip->storep; block = do_div(lba, sdebug_store_sectors); - if (block + num > sdebug_store_sectors) - rest = block + num - sdebug_store_sectors; - ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, + /* Only allow 1x atomic write or multiple non-atomic writes at any given time */ + sdeb_data_lock(sip, atomic_write); + for (i = 0; i < num; i++) { + /* We shouldn't need to lock for atomic writes, but do it anyway */ + sdeb_data_sector_lock(sip, do_write); + ret = sg_copy_buffer(sdb->table.sgl, sdb->table.nents, fsp + (block * sdebug_sector_size), - (num - rest) * sdebug_sector_size, sg_skip, do_write); - if (ret != (num - rest) * sdebug_sector_size) - return ret; - - if (rest) { - ret += sg_copy_buffer(sdb->table.sgl, sdb->table.nents, - fsp, rest * sdebug_sector_size, - sg_skip + ((num - rest) * sdebug_sector_size), - do_write); + sdebug_sector_size, sg_skip, do_write); + sdeb_data_sector_unlock(sip, do_write); + if (ret != sdebug_sector_size) { + ret += (i * sdebug_sector_size); + break; + } + sg_skip += sdebug_sector_size; + if (++block >= sdebug_store_sectors) + block = 0; } + ret = num * sdebug_sector_size; + sdeb_data_unlock(sip, atomic_write); return ret; } @@ -3518,70 +3794,6 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec, return ret; } -static inline void -sdeb_read_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - read_lock(&sip->macc_lck); - else - read_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_read_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - read_unlock(&sip->macc_lck); - else - read_unlock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_lock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __acquire(&sip->macc_lck); - else - __acquire(&sdeb_fake_rw_lck); - } else { - if (sip) - write_lock(&sip->macc_lck); - else - write_lock(&sdeb_fake_rw_lck); - } -} - -static inline void -sdeb_write_unlock(struct sdeb_store_info *sip) -{ - if (sdebug_no_rwlock) { - if (sip) - __release(&sip->macc_lck); - else - __release(&sdeb_fake_rw_lck); - } else { - if (sip) - write_unlock(&sip->macc_lck); - else - write_unlock(&sdeb_fake_rw_lck); - } -} - static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) { bool check_prot; @@ -3591,6 +3803,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case READ_16: @@ -3649,6 +3862,10 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) atomic_set(&sdeb_inject_pending, 0); } + /* + * When checking device access params, for reads we only check data + * versus what is set at init time, so no need to lock. + */ ret = check_device_access_params(scp, lba, num, false); if (ret) return ret; @@ -3668,29 +3885,33 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_read_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp))) { + sdeb_meta_read_lock(sip); + meta_data_locked = true; + } /* DIX + T10 DIF */ if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) { switch (prot_verify_read(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } break; case 3: /* Reference tag error */ if (cmd[1] >> 5 != 3) { /* RDPROTECT != 3 */ - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } else if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } @@ -3698,8 +3919,9 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, false); - sdeb_read_unlock(sip); + ret = do_device_access(sip, scp, 0, lba, num, false, false); + if (meta_data_locked) + sdeb_meta_read_unlock(sip); if (unlikely(ret == -1)) return DID_ERROR << 16; @@ -3888,6 +4110,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u64 lba; struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + bool meta_data_locked = false; switch (cmd[0]) { case WRITE_16: @@ -3941,10 +4164,17 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) "to DIF device\n"); } - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || + (sdebug_dix && scsi_prot_sg_count(scp)) || + scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } + ret = check_device_access_params(scp, lba, num, true); if (ret) { - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); return ret; } @@ -3953,22 +4183,22 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) switch (prot_verify_write(scp, lba, num, ei_lba)) { case 1: /* Guard tag error */ if (scp->prot_flags & SCSI_PROT_GUARD_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1); return check_condition_result; } break; case 3: /* Reference tag error */ if (scp->prot_flags & SCSI_PROT_REF_CHECK) { - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 3); return illegal_condition_result; } else if (scp->cmnd[1] >> 5 != 3) { /* WRPROTECT != 3 */ - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 3); return check_condition_result; } @@ -3976,13 +4206,16 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, true); + ret = do_device_access(sip, scp, 0, lba, num, true, false); if (unlikely(scsi_debug_lbp())) map_region(sip, lba, num); + /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); - sdeb_write_unlock(sip); + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + if (unlikely(-1 == ret)) return DID_ERROR << 16; else if (unlikely(sdebug_verbose && @@ -4089,7 +4322,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, goto err_out; } - sdeb_write_lock(sip); + /* Just keep it simple and always lock for now */ + sdeb_meta_write_lock(sip); sg_off = lbdof_blen; /* Spec says Buffer xfer Length field in number of LBs in dout */ cum_lb = 0; @@ -4132,7 +4366,11 @@ static int resp_write_scat(struct scsi_cmnd *scp, } } - ret = do_device_access(sip, scp, sg_off, lba, num, true); + /* + * Write ranges atomically to keep as close to pre-atomic + * writes behaviour as possible. + */ + ret = do_device_access(sip, scp, sg_off, lba, num, true, true); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); @@ -4171,7 +4409,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, } ret = 0; err_out_unlock: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); err_out: kfree(lrdp); return ret; @@ -4190,14 +4428,16 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, scp->device->hostdata, true); u8 *fs1p; u8 *fsp; + bool meta_data_locked = false; - sdeb_write_lock(sip); + if (sdebug_dev_is_zoned(devip) || scsi_debug_lbp()) { + sdeb_meta_write_lock(sip); + meta_data_locked = true; + } ret = check_device_access_params(scp, lba, num, true); - if (ret) { - sdeb_write_unlock(sip); - return ret; - } + if (ret) + goto out; if (unmap && scsi_debug_lbp()) { unmap_region(sip, lba, num); @@ -4208,6 +4448,7 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* if ndob then zero 1 logical block, else fetch 1 logical block */ fsp = sip->storep; fs1p = fsp + (block * lb_size); + sdeb_data_write_lock(sip); if (ndob) { memset(fs1p, 0, lb_size); ret = 0; @@ -4215,8 +4456,8 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, ret = fetch_to_dev_buffer(scp, fs1p, lb_size); if (-1 == ret) { - sdeb_write_unlock(sip); - return DID_ERROR << 16; + ret = DID_ERROR << 16; + goto out; } else if (sdebug_verbose && !ndob && (ret < lb_size)) sdev_printk(KERN_INFO, scp->device, "%s: %s: lb size=%u, IO sent=%d bytes\n", @@ -4233,10 +4474,12 @@ static int resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); + sdeb_data_write_unlock(sip); + ret = 0; out: - sdeb_write_unlock(sip); - - return 0; + if (meta_data_locked) + sdeb_meta_write_unlock(sip); + return ret; } static int resp_write_same_10(struct scsi_cmnd *scp, @@ -4379,25 +4622,30 @@ static int resp_comp_write(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); - ret = do_dout_fetch(scp, dnum, arr); if (ret == -1) { retval = DID_ERROR << 16; - goto cleanup; + goto cleanup_free; } else if (sdebug_verbose && (ret < (dnum * lb_size))) sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb " "indicated=%u, IO sent=%d bytes\n", my_name, dnum * lb_size, ret); + + sdeb_data_write_lock(sip); + sdeb_meta_write_lock(sip); if (!comp_write_worker(sip, lba, num, arr, false)) { mk_sense_buffer(scp, MISCOMPARE, MISCOMPARE_VERIFY_ASC, 0); retval = check_condition_result; - goto cleanup; + goto cleanup_unlock; } + + /* Cover sip->map_storep (which map_region()) sets with data lock */ if (scsi_debug_lbp()) map_region(sip, lba, num); -cleanup: - sdeb_write_unlock(sip); +cleanup_unlock: + sdeb_meta_write_unlock(sip); + sdeb_data_write_unlock(sip); +cleanup_free: kfree(arr); return retval; } @@ -4441,7 +4689,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) desc = (void *)&buf[8]; - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); for (i = 0 ; i < descriptors ; i++) { unsigned long long lba = get_unaligned_be64(&desc[i].lba); @@ -4457,7 +4705,7 @@ static int resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ret = 0; out: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); kfree(buf); return ret; @@ -4570,12 +4818,13 @@ static int resp_pre_fetch(struct scsi_cmnd *scp, rest = block + nblks - sdebug_store_sectors; /* Try to bring the PRE-FETCH range into CPU's cache */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); prefetch_range(fsp + (sdebug_sector_size * block), (nblks - rest) * sdebug_sector_size); if (rest) prefetch_range(fsp, rest * sdebug_sector_size); - sdeb_read_unlock(sip); + + sdeb_data_read_unlock(sip); fini: if (cmd[1] & 0x2) res = SDEG_RES_IMMED_MASK; @@ -4734,7 +4983,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } /* Not changing store, so only need read access */ - sdeb_read_lock(sip); + sdeb_data_read_lock(sip); ret = do_dout_fetch(scp, a_num, arr); if (ret == -1) { @@ -4756,7 +5005,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) goto cleanup; } cleanup: - sdeb_read_unlock(sip); + sdeb_data_read_unlock(sip); kfree(arr); return ret; } @@ -4802,7 +5051,7 @@ static int resp_report_zones(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_read_lock(sip); + sdeb_meta_read_lock(sip); desc = arr + 64; for (lba = zs_lba; lba < sdebug_capacity; @@ -4900,11 +5149,70 @@ static int resp_report_zones(struct scsi_cmnd *scp, ret = fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, rep_len)); fini: - sdeb_read_unlock(sip); + sdeb_meta_read_unlock(sip); kfree(arr); return ret; } +static int resp_atomic_write(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip) +{ + struct sdeb_store_info *sip; + u8 *cmd = scp->cmnd; + u16 boundary, len; + u64 lba, lba_tmp; + int ret; + + if (!scsi_debug_atomic_write()) { + mk_sense_invalid_opcode(scp); + return check_condition_result; + } + + sip = devip2sip(devip, true); + + lba = get_unaligned_be64(cmd + 2); + boundary = get_unaligned_be16(cmd + 10); + len = get_unaligned_be16(cmd + 12); + + lba_tmp = lba; + if (sdebug_atomic_wr_align && + do_div(lba_tmp, sdebug_atomic_wr_align)) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (sdebug_atomic_wr_gran && len % sdebug_atomic_wr_gran) { + /* Does not meet alignment requirement */ + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } + + if (boundary > 0) { + if (boundary > sdebug_atomic_wr_max_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + + if (len > sdebug_atomic_wr_max_length_bndry) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } else { + if (len > sdebug_atomic_wr_max_length) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 12, -1); + return check_condition_result; + } + } + + ret = do_device_access(sip, scp, 0, lba, len, true, true); + if (unlikely(ret == -1)) + return DID_ERROR << 16; + if (unlikely(ret != len * sdebug_sector_size)) + return DID_ERROR << 16; + return 0; +} + /* Logic transplanted from tcmu-runner, file_zbc.c */ static void zbc_open_all(struct sdebug_dev_info *devip) { @@ -4931,8 +5239,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) mk_sense_invalid_opcode(scp); return check_condition_result; } - - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { /* Check if all closed zones can be open */ @@ -4981,7 +5288,7 @@ static int resp_open_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_open_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5008,7 +5315,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_close_all(devip); @@ -5037,7 +5344,7 @@ static int resp_close_zone(struct scsi_cmnd *scp, zbc_close_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5080,7 +5387,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_finish_all(devip); @@ -5109,7 +5416,7 @@ static int resp_finish_zone(struct scsi_cmnd *scp, zbc_finish_zone(devip, zsp, true); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5160,7 +5467,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) return check_condition_result; } - sdeb_write_lock(sip); + sdeb_meta_write_lock(sip); if (all) { zbc_rwp_all(devip); @@ -5188,7 +5495,7 @@ static int resp_rwp_zone(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) zbc_rwp_zone(devip, zsp); fini: - sdeb_write_unlock(sip); + sdeb_meta_write_unlock(sip); return res; } @@ -5215,6 +5522,7 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp) if (!scp) { pr_err("scmd=NULL\n"); goto out; + } sdsc = scsi_cmd_priv(scp); @@ -6152,6 +6460,7 @@ module_param_named(lbprz, sdebug_lbprz, int, S_IRUGO); module_param_named(lbpu, sdebug_lbpu, int, S_IRUGO); module_param_named(lbpws, sdebug_lbpws, int, S_IRUGO); module_param_named(lbpws10, sdebug_lbpws10, int, S_IRUGO); +module_param_named(atomic_wr, sdebug_atomic_wr, int, S_IRUGO); module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO); module_param_named(lun_format, sdebug_lun_am_i, int, S_IRUGO | S_IWUSR); module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR); @@ -6186,6 +6495,11 @@ module_param_named(unmap_alignment, sdebug_unmap_alignment, int, S_IRUGO); module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO); module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO); module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO); +module_param_named(atomic_wr_max_length, sdebug_atomic_wr_max_length, int, S_IRUGO); +module_param_named(atomic_wr_align, sdebug_atomic_wr_align, int, S_IRUGO); +module_param_named(atomic_wr_gran, sdebug_atomic_wr_gran, int, S_IRUGO); +module_param_named(atomic_wr_max_length_bndry, sdebug_atomic_wr_max_length_bndry, int, S_IRUGO); +module_param_named(atomic_wr_max_bndry, sdebug_atomic_wr_max_bndry, int, S_IRUGO); module_param_named(uuid_ctl, sdebug_uuid_ctl, int, S_IRUGO); module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR); module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int, @@ -6229,6 +6543,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=1)"); MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)"); MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method"); MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); @@ -6260,6 +6575,11 @@ MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)" MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)"); MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)"); MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)"); +MODULE_PARM_DESC(atomic_wr_max_length, "max # of blocks can be atomically written in one cmd (def=8192)"); +MODULE_PARM_DESC(atomic_wr_align, "minimum alignment of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_gran, "minimum granularity of atomic write in blocks (def=2)"); +MODULE_PARM_DESC(atomic_wr_max_length_bndry, "max # of blocks can be atomically written in one cmd with boundary set (def=8192)"); +MODULE_PARM_DESC(atomic_wr_max_bndry, "max # boundaries per atomic write (def=128)"); MODULE_PARM_DESC(uuid_ctl, "1->use uuid for lu name, 0->don't, 2->all use same (def=0)"); MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)"); @@ -7406,6 +7726,7 @@ static int __init scsi_debug_init(void) return -EINVAL; } } + xa_init_flags(per_store_ap, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); if (want_store) { idx = sdebug_add_store(); @@ -7613,7 +7934,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 Wed Jan 24 11:38:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528995 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 9132750A94; Wed, 24 Jan 2024 11:41: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=1706096514; cv=fail; b=jnSObqyo4CknzG9Zirj2kWvoK/5rsGV5Fy6iWRgXSQR3TdzFk/N1e0hKH8nfeWJb5istegfYnDaGf5s3Pvf3+aIXQuNv9YHdPHq2QfJZJcXpNIy2S2Olb+MfeFhzvrm1TYk8N/HsZ/aS55VBKICb/Dt2d5rlw0Xq0W7Ih/LX0bo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096514; c=relaxed/simple; bh=S6f1cwkJCIX++aKJcUZ1t+kwWC1MVD9rKmWW3IkMtgY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=L2/1u9YBpVkcqEj5xCeDh//Cwg3Pg+vaZ84KM7UhLtQ32Ur5AqFnAGCCBhfbS/HvmPwrI1fys6I728g5WbSn/tFje7S896NsoLJsYw/a9Jg/S6KN9BT0iQaerhhVEV+3nwMcpUvZNQXGKgi4JeWu3IA0JXi4VQhdgxBE9TOhb3w= 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=BrUUxpyg; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=lhRDiLxL; 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="BrUUxpyg"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="lhRDiLxL" 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 40OAxSDD019689; Wed, 24 Jan 2024 11:39:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=BAz30FGSJKBWQdieIPEuEvrCdtFXnCfG/jKd13sqpvM=; b=BrUUxpygMY4wXU589Q2673jHxoY+DobQMh+blmZAOQOIHbGnhJTpCan8fJGZVXQx3hwq JOQPhgvszmIvT+/ahigJcLibzXRuMOO5d5dBfAcDFzuZ4Z0KS5l7mhSoAp72szdNQ/Po MjOxjXdErSx1rbtyT3Hy2pddEwR6sctz+GS4noAwLw/FSlQqFFBVIagreRNESULVbMUp gRsD+N1egnnQS9QSZrZOlRwx2LPL9xuOl2C5n4fWaHivRmkgMFJgh1GNaZyJV/+5toT1 kyXR8OFAvM2RMFV4USkZNeVnm2JzLC3SnI7pDA/+eG3oQskiygzewVBYBSg0im4g7IE3 /Q== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7ansx9n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:28 +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 40OBPAN5006158; Wed, 24 Jan 2024 11:39:27 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 3vs32setbq-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V55suHW54Ua7Rki+sURSc+xJF/LYClsE6s9oJUbrDkw/B1wo9Dh5WN3CzbqKJ23cul/E6iG/H7tB+Vey0RL5x6a8nLulmO/QmwYVY/5iWXe6ezfZKo72ZiFI6zK8uMKnN4J5bkmtQcDmBYWc0iRRYoPWQJQZnZNl6cJLfOLDeZI9ew0lI4CIpAu8ikLS+2SUJfZw0D2Bo+KEH7RtuLF9xGZfCCbu+xDYlccwyj4SlCpZbsl0/oUD2er5pQpdifh0VgNtwMnYTOcEVeO8BjfwHPrn7VIL6pDTF9JLRpsUY4oTtMEbou+cukD6SPViNsY7zVuUExKFFBtedAPGFS51/w== 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=BAz30FGSJKBWQdieIPEuEvrCdtFXnCfG/jKd13sqpvM=; b=TFjhNKkHV7yydzEmXaUNqCG1IIhQQwAEHXnq1wlqqg6eAHZg1ZfJ2i7i9BLKbAkd5aTdGSpp7TP2BPa+JWJG22jPBbnEBUjM4ao960SfSZ7HnYjW42Dtk3rWGDDpB4erPj+IHtB/v3qC2x19HT2OgK6z7CAeYpNg+hDOPnZDFu7BnVD58uuQuCUgP1evS/NU29zBkaP1ZOqp5hFCKT7ETdrujMJ7rlq4J67JxDu3c0mCrNi+ZGmWtFshyeb057aDZJF32tLqRaprxaNMDX2j3IrnP1N8w7ruPtsPjxISYOs9c5wJ7reFs/YySryj+U/Dn+X+YzmJztudgdxAgk9hLA== 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=BAz30FGSJKBWQdieIPEuEvrCdtFXnCfG/jKd13sqpvM=; b=lhRDiLxLaIT6ftXIap+JckQk9cz2Dz2dqU9+SKd1kIjyFPb6QdFFPVNtlbMYNnk1OAHzngArTiclAiQCVoqKXwGP1mW7ie1il6tCIjCwHrMDv9KYQ6AUb6CqLGfIEULXov7mMQGAUO9zRsL00WNLZJyNzlTR0bhT2eHaol3pS8A= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH7PR10MB5815.namprd10.prod.outlook.com (2603:10b6:510:126::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:24 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11: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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, Alan Adamson , John Garry Subject: [PATCH v3 14/15] nvme: Support atomic writes Date: Wed, 24 Jan 2024 11:38:40 +0000 Message-Id: <20240124113841.31824-15-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BL1PR13CA0290.namprd13.prod.outlook.com (2603:10b6:208:2bc::25) 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_|PH7PR10MB5815:EE_ X-MS-Office365-Filtering-Correlation-Id: 468739b1-6f45-4f62-76b9-08dc1cd11d0c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4GoE8z//j/3QIFIHJgwZgl7aS9Ve3AmfGVEx/ImnPrMrCZjCUt3jL1SyRmR9OaYbyOiA/W5jxi/mRmJn6cZEIevUg93RcBGGTrUtymHqJkt95u2Uka00R2V62kH385yJYuL+SI584TVhLmhg5FI+P97N9/gC948HNUKA1KfsVLBVwClSyKLmzUyP3R3BkDExCixPfmm63Rj2LbkydiyOZ8TA7udC846IhiCRhOnAtCuFP+wvkQHbqCU6yjSt5kTgnLBobs6msg5do7lDFo7woMxGSKtFwCybSI8PUwFDj8Cs+MyXZrE6n9kaMOkex4ckUvlw2qzLoHyWB4cUNncoyed+JV/0yLFH9878+HN5I8kBiCRW9SO7q4cWzrTBspD3VIn5LSYTAmiaqZ8Sf0YrLYofLIgJ+QYhI1AEEJJVjpWKdCRQNPY4D4dxLD/JCDCPTfj7GdpewxueE48QYQvTQsfCiiKHStXmrDRodNBJDyzljleFQAxetjKvsw6q5cDcECnpz3xN6V4yrWr8ywDhBaLBKfs+MfuaDM2ZJjb2JEny+18nOwbA0SMjA10kW2U0bhrvt7CuIL6aAxN/zjQu3qJXJX1ItpKbQ/u/yBAVQEU= 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)(376002)(396003)(136003)(346002)(366004)(39860400002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(83380400001)(41300700001)(1076003)(6512007)(107886003)(26005)(2616005)(38100700002)(6506007)(8676002)(4326008)(8936002)(5660300002)(7416002)(2906002)(6486002)(478600001)(54906003)(66476007)(66556008)(6666004)(66946007)(316002)(921011)(36756003)(86362001)(103116003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wGRijSKK82H/jaqh3sLfp5JQxNIKUpXmZdCXXj0Dk0T7uCSxMw9W/LtNF9WMKPuMYxMio5b0RJ8Mlb/pW53OVpXWYE3YXlrDOBoe+EwbGY7ffOUUTQjOQBMduZ52lZ1MC887Nr7TuEzV8gsTzuoWml9Omxsvt5CyIkJbPTwavWOlotXB+cypU478VQOLF/InqWUZL0q3QkhaeWa+/6fQN8I23VWeR56u4cKZLmimx8JNeEsKoL3Hujd7I5DzVStEdNp7DRb/bX+B6DBLJ8ob1hQoV6S5mmu2Om2NJ9BfGbW0MbWyhOuFraBxuC76sQYKbT+xXuzWshY9mHtAeIfpSzkUhVrLQ51FCp6vjgctqoym3mPp3/csQi/X6cj1nPqMZjb1jXzSGN6h6y9qzx6BY0Ih64i+MSW6GJMBQbpKirY9fo9+EdpIKQDLS2W7Om0BgI6enay8u6g/HgqbFjp+J+L2K17Gb+8cApIRGCsK9TA0jyMh9vUapYcM2pDz5P8vHuoxiC56cURL4J2GB/sbBviGMFNB2wVwtAtMCt3sAyra3qMcrYifvWG4LcHgvR3ifOoPzPkZLAQWvMSoizR++8beO1yFnKQLp18KuNEsYXxPex2OYCiCa8kFKaWGNKlilK7gyK/oDhF3S0dVjrxsIAChRvz7RWY/yOC6cGoN7uH7Q7Mv1KhEEuuA9vJK9uiYAGNz1gJ1cvx/D5KUAYD+fbwoDNpkIyb1cCsoDpyOOxm2Jq0kv2bnjLq88kNYhu+GdmW1OGpjESx3Xaal4PMQnEB8dcwWb2eSw6ndLnatRRcZQ1hqFKq0W5Mq0Ob4V5P0b215zmJgpt6JjMmLGOWtT1EvuW55bl9bdRtodpNNkr8f6aUsvCTatso4h8P0SZeY9yPQpqgBx8nsxRVLjaakA91H1T4vYxfrXHYDH99iC7DbqnYrEJc6QdxrDWz9wI1G4MSE7sTFuIfLYzMhoGIFtvXPhKwd3WZh1j26vIbWykSG3QRHD17R8oL+7SB1476KB2qQTCR5Rz8VYtBN7Xltf6gtJbbRLYhBJ2V09OlmX8kCEaNXcJ8JJvBEUpKPaOM1f11drYHWYwihqz+Uo2li6+3OaiylB38s1Hey+00z5J2qUOdQjyiCF5nhsIpi8XxJ5dCLPYc+1QEgvpIo0abwkVUMn1t1X1yebnBqDyExHpYwmUb9o6hMluxAfjpKUJZQwWer4tIzUET+LNXks2uvd9cTdX1EzWqY7u6PnTma8Zzs+iaqjYLTrRtiyrc3Kv9lD3/d65AN8whwCAGlcTy5FeCjyhNVVFvvR7dcvBJc25n32qtsZHbcIEOkIrvha+NfTxiU/Do9yJQwOju4pV4AKptQbGS54HfyWj+wTCB1jyPEO81KEyAAbj2Oc9pzJvYi494ft/xezzbaz9UWVSugl4Vk5RNfpN6UwGuiN/23/lKsC9Dfrn66giOXEGIqoi5z8koyGv6rm6PCS+TeaRL8yXhmIogUMOGEz7RQKANldpU4GuSwd47q1HDqUchUM1t7ta3Mq8bMFUylyGIVzGt0cCwyPwQB07Jq8GlnwkprTW8YHsCs2ta/wsj8Kh8D18G6xksDHCQxNZ0zhKbi1RKJmQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: yQKTsQYE7OYh3bAbKBAxsQYptkiQL5TkL6+H2alcMY9oyzxVI02ZJ4S+arGZHTxbmvHNVhIFO0OJF83zcOyTfR/odi+y8rdRZ5787nqgNwXW474N/zRMoPhJ+GsG6ufg5wybOkArB8hHHkkYpit0EfOOKOPy1J59azrfrqCweItu+848ZYA6sSe5ePlJSuQlI3XEIFR+5+Zmdm73jww00S86HZHYkicMbGFY8YAc4kwajpQYcLoHyAzbl5FSBJrKyClGNibppDz6caMj08OtkFlYH7CqSmR4GGS12ijbTLuQNtWwKKoI+azVW1/SiCVSjslE0Hus+sCGJEDjSACAAdzp0u/Gwn3MoAW51Cq6eyUHgt+yPA74FaGM74279ogY0AqAaf7o9/QAM2NDCKecoqfsV1z3upGxUsJpCvhNOtxgNKZZ2uHpF0Pk/u37tdt0iWYZ9IxK/czMuJkHALamYQ9BYsU7OPlarhVJe1M8aOcuQjHHFgCy6ySQXV/i2RwIIqR8b6DsMqUBCSo9jXK5DYH2pvfcQpxvM4G44Hy6aDtBK2oO/rVI28kZz2YZYjYRkMkc3+exW7Pj3UMVs7hq33Dl31+P1KrvwA/7Utbiakk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 468739b1-6f45-4f62-76b9-08dc1cd11d0c X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:24.1887 (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: NF3zqRoFschKiVEqXAijQzDHHdb7k8Tt5txIOnzarqj0qQOBB3AGf3vv4E0yY3YK4TzRafTSf66QAbk2XO4kQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5815 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 bulkscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-GUID: ubca-UJOmyGm77r0jJ8vO84Sbo6DBAjt X-Proofpoint-ORIG-GUID: ubca-UJOmyGm77r0jJ8vO84Sbo6DBAjt From: Alan Adamson Support reading atomic write registers to fill in request_queue properties. Use following method to calculate limits: atomic_write_max_bytes = flp2(NAWUPF ?: AWUPF) atomic_write_unit_min = logical_block_size atomic_write_unit_max = flp2(NAWUPF ?: AWUPF) atomic_write_boundary = NABSPF Signed-off-by: Alan Adamson #jpg: some rewrite Signed-off-by: John Garry --- drivers/nvme/host/core.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 85ab0fcf9e88..5045c84f2516 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1911,6 +1911,44 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl, blk_queue_write_cache(q, vwc, vwc); } +static void nvme_update_atomic_write_disk_info(struct gendisk *disk, + struct nvme_ctrl *ctrl, struct nvme_id_ns *id, u32 bs, u32 atomic_bs) +{ + unsigned int unit_min = 0, unit_max = 0, boundary = 0, max_bytes = 0; + struct request_queue *q = disk->queue; + + if (id->nsfeat & NVME_NS_FEAT_ATOMICS && id->nawupf) { + if (le16_to_cpu(id->nabspf)) + boundary = (le16_to_cpu(id->nabspf) + 1) * bs; + + /* + * The boundary size just needs to be a multiple of unit_max + * (and not necessarily a power-of-2), so this could be relaxed + * in the block layer in future. + * Furthermore, if needed, unit_max could be reduced so that the + * boundary size was compliant - but don't support yet. + */ + if (!boundary || is_power_of_2(boundary)) { + max_bytes = atomic_bs; + unit_min = bs; + unit_max = rounddown_pow_of_two(atomic_bs); + } else { + dev_notice(ctrl->device, "Unsupported atomic write boundary (%d)\n", + boundary); + boundary = 0; + } + } else if (ctrl->subsys->awupf) { + max_bytes = atomic_bs; + unit_min = bs; + unit_max = rounddown_pow_of_two(atomic_bs); + } + + blk_queue_atomic_write_max_bytes(q, max_bytes); + blk_queue_atomic_write_unit_min_sectors(q, unit_min >> SECTOR_SHIFT); + blk_queue_atomic_write_unit_max_sectors(q, unit_max >> SECTOR_SHIFT); + blk_queue_atomic_write_boundary_bytes(q, boundary); +} + static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk, struct nvme_ns_head *head, struct nvme_id_ns *id) { @@ -1941,6 +1979,8 @@ static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk, atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs; else atomic_bs = (1 + ctrl->subsys->awupf) * bs; + + nvme_update_atomic_write_disk_info(disk, ctrl, id, bs, atomic_bs); } if (id->nsfeat & NVME_NS_FEAT_IO_OPT) { From patchwork Wed Jan 24 11:38:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13528996 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 51BDC5A0FD; Wed, 24 Jan 2024 11:41: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=1706096518; cv=fail; b=HkQgfyKeMQzJSFEd/JZRpZBgtI8DoxpMoc+wuZi9BpdxelyzGfkXMcnS+pV+qAcSDo9/CCtTovY+Ty/gfSThn6aL4nh4XF/vYJaeVEUD9OwEV3+qAhoogrZFa7Sl7vmjlwWKwuqKr8Ck3dK9f+l8hTfmueVlWshjm0rmfZJNMRM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706096518; c=relaxed/simple; bh=XzntPZElmNiA0orUKM5b/hUv+unn9WgT/QsNM0aqJU4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=XISbxTMznZlA+Hruod0Y1aRNrgzF02NuEoEz2JNMH2IJu6ClM9eXJnT5alQw1hKzBGZ23+jhQbDpvTJTPQle23VuYWsYAffR3mAq9Yy/KUm5SAqPKY0FZlgGAgWFCdPeMWfatQxXoXYfQrJpfieD5RiuJQF9AU5571Q1PqZXP+c= 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=HLFi+9cy; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=IgVSLfd9; 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="HLFi+9cy"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="IgVSLfd9" 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 40OAxPEt030725; Wed, 24 Jan 2024 11:39:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=cTFWjnvbEsuX81EMnFt9l1cWFwz7OYTI5W7kirGCqBk=; b=HLFi+9cylamqxG7WvRKvLVOfX7tl1dcFhW+e41LqIhOw0eeWtdlS0wml5acmZCPHbwlk qqUwM0OsgoXnKorxVg3RF0cm/2Z25RfSREg9UWfLh2qSzCx9/UT5/Hj10Zuh9qM6NmLv nG89USF5W+BCw5yIEDNKOa1QbCEiKtxhg5QO4WLQ0NjeXDGMBiavl6urciu8HS3TJG2l Pv+4GRyhvXWox28kmLCuz+Sg7HFLWMOLGY4MDUEvMOuzwde8FmcJ5BKzpfU0lmuUTdbI pTEuyClrwvBOLlLUU7gZDRI+3SA3fVRxn91k8ykqP/BslOedC2sKl3CYrBmO4vmU/Zue pQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vr7cut1jh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:29 +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 40OBVKx9001442; Wed, 24 Jan 2024 11:39:28 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3vs323xf1b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jan 2024 11:39:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WJnaxdqvyzgcqJMdCEDFT563jRAVQR/kwN5IGqruesKhxxad1nKBu8dB4pXfYHQ15OaC8V8UwuDeFJRKoAL8BTkilOnLJiN6fafqyapFWiskGTc7BokULkZNtxd7wlKBvXtAfSxV9toqNQwnnC+jjzZzyuoMfPfohh9cYpQw3gHJtHvcw5tjsWPQ6lJ83kKNALn//39v8TQwfNOJXnVltZnyuK9Tnnh5aHu80gPEYoDWAVEtDJz/r7EW9In0+JVCSqCFs8V0ufon9C4B60rgVIw8NrJhsducMZpP7pb4JINmYeyaYHJ9Ge3n4nCHW9nC2hgU9JT/fPb5wYZart+Kag== 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=cTFWjnvbEsuX81EMnFt9l1cWFwz7OYTI5W7kirGCqBk=; b=dYR7SDp9vn/kz6HuQXm2nUwhLzxSelNoY48BUf82jC3siZpsBhwr3UD1uc+3eeWkN8BGB930+wrvII/+J7mgS2v8RqZScMuHElCVtOxqtfjRskTKvrpAdaLtK2Y3HDVIggDDpSHFU/nVdHMAD4BtQI/mAGxAJv92hbFr7XiwNyTN2Tpw7mfYZEe3gmjfWKo5zXmXVLeuhHnwXzxN9XsTpKL5KxX/WuJlVySTjgougr/OddFQXxArXWJ7ic3SNpfr4q2rxzmKuSktocAW869VLCzFiv1Vluuv8gl+04X1dtTT5C/VX/1fZB+LcjRwFgomsXEnXIOTiT3rva1K/+UmvQ== 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=cTFWjnvbEsuX81EMnFt9l1cWFwz7OYTI5W7kirGCqBk=; b=IgVSLfd9+BLsE6mc3JLdgntxBbEup9+Z9QKBbF9WAgMUQqw/tnaXk0NHJD8Q+l6E8sJ+K3HqZph0TQMmexjrnpZkqdqh8IZqtNxucp4RI0VBo9AEKmg5OycYCzUBbXbO+ngktZrW5qMPZgPFsHaBbWWoFXj0VJ7DBql49Q8oXIc= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by DM4PR10MB6719.namprd10.prod.outlook.com (2603:10b6:8:111::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22; Wed, 24 Jan 2024 11:39:25 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::f11:7303:66e7:286c%5]) with mapi id 15.20.7228.022; Wed, 24 Jan 2024 11:39:25 +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-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, tytso@mit.edu, jbongio@google.com, linux-scsi@vger.kernel.org, ming.lei@redhat.com, ojaswin@linux.ibm.com, bvanassche@acm.org, Alan Adamson , John Garry Subject: [PATCH v3 15/15] nvme: Ensure atomic writes will be executed atomically Date: Wed, 24 Jan 2024 11:38:41 +0000 Message-Id: <20240124113841.31824-16-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240124113841.31824-1-john.g.garry@oracle.com> References: <20240124113841.31824-1-john.g.garry@oracle.com> X-ClientProxiedBy: BLAP220CA0009.NAMP220.PROD.OUTLOOK.COM (2603:10b6:208:32c::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_|DM4PR10MB6719:EE_ X-MS-Office365-Filtering-Correlation-Id: 89741e9d-331c-4fcf-7a86-08dc1cd11dc0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lfYMIy4QsZNF+4xRFfcp6CxKBZdFu7psaOR5YzqFUocFDXNm5LYpwqZB7CcQFpcL6CccVJmxSC13oma3Ic6g/gbAi2U6oSPQ3le404uZeZ6ZrzE6exCI90SU6v+ykolAoIyssXy9jTbntvEd5C3DFdEmT4PGzDwrUpyWN18AraLbdqKMMtshI2bVz2n7JdOdNmRiJU1PdstnNb8TYaNls9kT3RWR/E+t++nucEB6fVmcvWtGvHwIaVGDI7S+GlvM197TDdbxVx8q3mvt9OY03rnVdRlev9m0Jr5mSJOpVo82jaztqvztNCGj5U5kyU76YERlBZcozofWsdJMZvqyTuCW9DETyxPjIXbLfzEF4jIGxSsmdjbwuLKcf06PPbgaWLKaJwowwV5cMxO9X4JgpUmvILuf6wVwFKb7phM1cYKlq5HI5b/QlXJ8e6O/IpADmZPEDH/rXRRGbnl5vJVxke9cy7UBLyWcDWXfYkO82l98Cxb5zaXOO8l+JbGw6q+0zf8dWlK7aJsdCPSqO/UZ2d5vGNLpWJMro+twR3eQSS2pjT9bqTm1x36x1DCadtp+iZEIvcp1CVs0gxqK8LbXGE34JITQzAlCwCff69pxq10= 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)(376002)(136003)(346002)(366004)(396003)(39860400002)(230922051799003)(186009)(1800799012)(451199024)(64100799003)(54906003)(316002)(66476007)(66556008)(66946007)(83380400001)(921011)(7416002)(38100700002)(5660300002)(86362001)(36756003)(8676002)(8936002)(4326008)(2906002)(103116003)(41300700001)(1076003)(478600001)(26005)(107886003)(6486002)(6666004)(2616005)(6506007)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xlVzclSmEd/I9JJVQpehK/TPLXPRe6AhqBPfrkGp7ELdP7AI+LssrU3p+sAY6xz5/OfD2UXsETPcWg3XHEysXKcrOzI3BUh+opC/fxssvbQAsgVZbBSxTPKtcYIc+dKRt1N7Ob6n4MDvVmDvW602k7K6QK48XGg/jA90h+u+bAUjqljK3K1Mhk3BJ1SlFX0Kj9WVYxPMpoaykOmGsodvQM780b+59kWVx656GYXQ05LEAaGVF74RWrRVIHHM8TXBq4XI3canKpJBEXpnXMG/VV1BJ5BPvnRfKcCRF/Bj16gWVhXoViJpzGeWINmtn/EEpDRd6niF2NkbNrsLaqSMnmc0SzZVLUmOBFiaUvNwu+RK131+UK7oCyc0CI91+ZdAuV9oyXQbVbGRFfeAR1ft/ELLXPNRk8TqVpjUgwN83vepzP9G2o7GZtVBJQfZ7MBavSMOOyatNcFjXNuPZnjQ/oa3HTcrM94bPIKpYiNBFK3hA/irltfmYsOgWCZsrIK7I0CNPClvtAbgaDs7sqpywy/rmsZbrdKMEjGA0GakE9qirvx+FujZpBk7+Lcas3uT+eECqcDm14KS0TL+7aEziJIB58N+spuQFGh/MgCGsHAj2PvP3vPMrZh7DpKVxYOT+stmxYSf/km+VvHphq5MeH7fDfkZDQT2Yem8gmUY7HCJSqgV1dsLasMx7pOMqmYcBULNQVIFBoGRiAnBUwIHLZw9vqPHDLnRjRN4QoeOMEJ2GaMGGm6oZ6zarMup7zrVZtDSSXGcfso8RGE68awEgHlKV6JeZytXkeS71F7eTQIuHHx+6maLetub9M83SIbkjYiQfL16kfehpxObtlDRwUISklJtAjJzZaHpqnBT56TgrVLdhUteNShbAmz/KQijyPiCzeJqMPFzUzKipruo5EG0w8i51hzQY/KP7bGcrnTRoXHLCk36EXRnEnDNihWcEsAJhNHpld8BKl94wuO9ACX4fcyZGtBPOzXvp493ezzJEwgEuJY6eCnhmzL7AdVcfXEqgu1G3Gz/No08W7ypyChjf4zUWReM3BSdnkoomO5+NsvBMx29jdAQBTMjHLjhx3bWoTlXp0adZyPop6ouCQ2jXJUx5w5RZmALzyHTImiQbdpls7Rvgmjkr8kk2Trj24EA7+YhJm62c+6OVFKLrL8EvH1J0R81xrj/d32AymrjIwifAeoAjz6AVt2wPSmQ3VsoLzDeCjPsJRt3jTqC04o0h6V64k0fKnJYp0cwpiPe4nH5hA3K6sbgJ83s6t4h2uE3YE6v5rSjJVFxnB0Lq8IDEzmQzPRojuFhkz9K6nZ3BxaERASzZ2din7fX+p2VVLaJBoarQaQh0MCmCe+WujMXvvA2mgwPmRrDI9PDPqcak2zbX82H1RxK8exMCJ8UJh+yce9OkNnLtX94/HruQXy+HfiJKyGQmJJ8vd3oVdwreDJOOSg93vIU5nHktSpfml44zW7C6rJRp61D2qn7SAp6TpZaLZtIV/OF6j58FSEIqfL1wr1Qky6VghDc8ZseZfSlYpcKcAG7QkZKP0j2iZAwIIJNoXGp+xwUq/0v53372BsAhTmAqp3EB1uk6OSkvDC+bVJwSiwf+Z9oRaDKLw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: r7yZag3rEHUmOtbqfkxkHLm9kNJXIZEgdgzGTjBeFoPxqyUQddQ6pm1+GUTdEL5HA+yXBp7qibameQCQo2mWj6vqAFy/B85/cIkCQe2tNLCzRE0FRElxb88YP7x9GVTwu3gOQcv42KtN3AEWbqaxIbUszUGCS4ZMnegcHkAYGWpgz0GdPraOzvXjSh82REgZiPyUVdXjGcWvld0f4eJ0DrRuo7XpK30YqLMWRBWf7zQUqvaORdWWMasFk7Ba/3hJcRIvQgnzDIWYChQp5w+lpssVpD7fWn0ElrrooKk7gRM0/eToPd4Vvhal44l44VimbE1RQpjlKpBYUH5MbqGvqQNjgQH9A2cmc5vm9bWhCOsoBPU1ZmsuFgfIrSEWGVgFe55c9Si7pj48NZU5xLJH2WWGkltKhNJ7ag7QL6P3Dz8NEP/2TtvPSavZyNmvQMDka4taK/6jtTn6U2SzRkBVsweCD0VMUaxyJ1HLUcYdLiy7tvXBtsU1Y9CtAsX5AqFCTBpCN2nfsQbb6hTMolCo1AaMAKbdfnl6/cUKCk/jWhBpm5sB+JB/x9YycVIci0Fyqk8DqCRvq0Xz3iN5xki6Pvzmz1qCpSzkaHhiZaE5aoQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89741e9d-331c-4fcf-7a86-08dc1cd11dc0 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2024 11:39:25.3772 (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: jw9e2LBsM2sv3NOisXuB6vyxVlQ3NIZtRqBDZKVIshQQxtl2h9brjqZezMdh28OkWc7jm/Rkk0228ADq+HrivA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6719 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-01-24_06,2024-01-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401240083 X-Proofpoint-ORIG-GUID: vU08l0Vlv9LhDEsWmP3MUho7CIcTXHLM X-Proofpoint-GUID: vU08l0Vlv9LhDEsWmP3MUho7CIcTXHLM From: Alan Adamson There is no dedicated NVMe atomic write command (which may error for a command which exceeds the controller atomic write limits). As an insurance policy against the block layer sending requests which cannot be executed atomically, add a check in the queue path. Signed-off-by: Alan Adamson Signed-off-by: John Garry --- drivers/nvme/host/core.c | 35 +++++++++++++++++++++++++++++++++-- drivers/nvme/host/nvme.h | 2 ++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 5045c84f2516..6a34a5d92088 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -911,6 +911,32 @@ 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) { + struct nvme_ns_head *head = ns->head; + u32 boundary_bytes = head->atomic_boundary; + + if (blk_rq_bytes(req) > ns->head->atomic_max) + return BLK_STS_IOERR; + + if (boundary_bytes) { + u32 mask = boundary_bytes - 1, imask = ~mask; + u32 start = blk_rq_pos(req) << SECTOR_SHIFT; + u32 end = start + blk_rq_bytes(req); + + if (blk_rq_bytes(req) > boundary_bytes) + return BLK_STS_IOERR; + + if (((start & imask) != (end & imask)) && + (end & mask)) { + return BLK_STS_IOERR; + } + } + } + cmnd->rw.opcode = op; cmnd->rw.flags = 0; cmnd->rw.nsid = cpu_to_le32(ns->head->ns_id); @@ -1912,7 +1938,8 @@ static void nvme_set_queue_limits(struct nvme_ctrl *ctrl, } static void nvme_update_atomic_write_disk_info(struct gendisk *disk, - struct nvme_ctrl *ctrl, struct nvme_id_ns *id, u32 bs, u32 atomic_bs) + struct nvme_ctrl *ctrl, struct nvme_ns_head *head, + struct nvme_id_ns *id, u32 bs, u32 atomic_bs) { unsigned int unit_min = 0, unit_max = 0, boundary = 0, max_bytes = 0; struct request_queue *q = disk->queue; @@ -1943,6 +1970,9 @@ static void nvme_update_atomic_write_disk_info(struct gendisk *disk, unit_max = rounddown_pow_of_two(atomic_bs); } + head->atomic_max = max_bytes; + head->atomic_boundary = boundary; + blk_queue_atomic_write_max_bytes(q, max_bytes); blk_queue_atomic_write_unit_min_sectors(q, unit_min >> SECTOR_SHIFT); blk_queue_atomic_write_unit_max_sectors(q, unit_max >> SECTOR_SHIFT); @@ -1980,7 +2010,8 @@ static void nvme_update_disk_info(struct nvme_ctrl *ctrl, struct gendisk *disk, else atomic_bs = (1 + ctrl->subsys->awupf) * bs; - nvme_update_atomic_write_disk_info(disk, ctrl, id, bs, atomic_bs); + nvme_update_atomic_write_disk_info(disk, ctrl, head, id, + bs, atomic_bs); } if (id->nsfeat & NVME_NS_FEAT_IO_OPT) { diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 030c80818240..938060c85e6f 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -476,6 +476,8 @@ struct nvme_ns_head { struct device cdev_device; struct gendisk *disk; + u32 atomic_max; + u32 atomic_boundary; #ifdef CONFIG_NVME_MULTIPATH struct bio_list requeue_list; spinlock_t requeue_lock;