From patchwork Sat Aug 17 09:47:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 13767112 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 2F10914EC4E; Sat, 17 Aug 2024 09:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888125; cv=fail; b=fKlaWqusd13OdPiEOeVgiN0IQ8nJuw1ZyQE/3h/RG3WwBw13YuYJaBUq+Fwv3hgcVQ6WY8BUhJQqu87DHpg8h9lXqsbriYktEX7UdzSPC10O2EMmXHMzM3Vu2QmE5kfg00EvfgGlSk1C3EdEu+rxwLhCgJz2wLrrAdCyPk8RsWE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723888125; c=relaxed/simple; bh=D4aXnk8UeMaPh0XQlyOSWm/OMrNuFw7/bGsduXlbJAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=u6PwQCpOLtZIVaGGG64b7aEEIlB9ndj5nDl4mYkOUc0J+Ca4TUqYNJXsXgFUsxl9K+3wsg3/IrXFysFc+oBehlJHwSNvbpHuhXpN8sBqs9nqwZbSWED76r11GtqUYmykbBH41mi+O9RGz0DvOKGhVj+Xjk3Jdjm77EeoU8/7RCY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=TM8yJKMM; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=iKxfI+5M; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="TM8yJKMM"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="iKxfI+5M" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47H8G7I3018252; Sat, 17 Aug 2024 09:48: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=XBgSR9D8hHZU1SortIL7gHTZlCU2PByJAQHBZrYkVrc=; b= TM8yJKMMgLEOsff8MzXODQRzxwZ3fkOwAltf8PvvgN1BlottbQLIx0muBAb8PlOJ G1PRHvZ3I9dzImQx0NHoHo6jdX6lC8Xa5SAMuQYJBGnPLQe0juoNnYsvS/m5mL86 EX3vVZSXAlm6MuLFSqJXveAgXbfXwg76Aw/GAzs5Ga0G4knHVQYjzBp8aeKcOgXz uKTGEroB8AIvaRKhLp71TrGBV7/5TtCC9C/iUVaWXojzHQ1gIl5hl1nRlfIWr9vm GpTr/FxUjMkeXjmAjJeCXxDFGLlJhLgMStUor4GtTVM3yuX5cy7O2IDIEpVjVmPA ILP3/8XEbAREeNiqTmqvCA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m4587mu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:28 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 47H811UK031437; Sat, 17 Aug 2024 09:48:28 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2175.outbound.protection.outlook.com [104.47.57.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 412ja5y121-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Aug 2024 09:48:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Va8xUixT3hipfP2wiVvG5l4fEhZZMbWBABKrQpjDLko2O9sdmM2myICLj4IqvV4S/+BRGTo/9Gi2qD897LFJbHpt99RmeUaaVESNWPQJAUNtIQ79UbFdjMbGTCV4742LGZ7L+5RhNcY1/Uu8u+mcVMnFkbcCxYhgSGPHD6yNWaNEMfiHf4W4dcfrL0WAueaSrLqzpOOYsODXFUa68+FfndYJd10fs8tpGJ1Re1TbQsKpsls6NVnopHo4W4hvGAaCU5TU/Lu8LBZwPy0a9qNyd1aeJD3lXuatFN5wcBsy92FTUakRB2h6FskQaFapEnVDjzSRz9GT2Loe8SWfQUVwbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=XBgSR9D8hHZU1SortIL7gHTZlCU2PByJAQHBZrYkVrc=; b=WKJsv6+Usl5c2Cg0yavbWSn/dpmQM+7bGPD/v2GSRLC3RC4rjCaxjS4ndvcURjZWDNcpu1bmvMyhfM4EF7hpgdt5Va5APYzPq7KIPpMzC89VtGW1t8B2s+vE+/NiyiTzvCudUXr8AG8N+EuUB/TN7uKbvDhkvEuouPuZUoGmHQ7nnwFkagtQv9tnB2EjvDRbjjaXnUkQrs5zBzN52/99sYobpR+EbCyg5vz8JErh5y9mgtS03aj78yl9qBhy1MQ6bufdvS8ZJPP09tZugmFWIe2WN+7WLo48HMEeM5g9lsfr0NXZQgq64SYc7pyzX2pVtBp+hSz2VllmZ7WCMZO/8A== 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=XBgSR9D8hHZU1SortIL7gHTZlCU2PByJAQHBZrYkVrc=; b=iKxfI+5MD737PayY477xKQJ1pL4UgA2m/5p0poJGNCu+tVlFp6tt1Itl8ELCG6iuMih2OQQ4VO2TnPGVhB2rqj+P6UuTWs8yNVH7fdLPHZOqfcT9p4krd8YFPiJcYEQIccRc9rqz1kw6VpIKbP+ERp0axwcDiWZtLEb9b/ExEGI= Received: from DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) by PH0PR10MB4758.namprd10.prod.outlook.com (2603:10b6:510:3c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Sat, 17 Aug 2024 09:48:25 +0000 Received: from DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088]) by DM6PR10MB4313.namprd10.prod.outlook.com ([fe80::4f45:f4ab:121:e088%6]) with mapi id 15.20.7897.009; Sat, 17 Aug 2024 09:48:25 +0000 From: John Garry To: axboe@kernel.dk, brauner@kernel.org, djwong@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, chandan.babu@oracle.com, dchinner@redhat.com, hch@lst.de Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, hare@suse.de, martin.petersen@oracle.com, catherine.hoang@oracle.com, kbusch@kernel.org, John Garry Subject: [PATCH v5 6/7] xfs: Validate atomic writes Date: Sat, 17 Aug 2024 09:47:59 +0000 Message-Id: <20240817094800.776408-7-john.g.garry@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240817094800.776408-1-john.g.garry@oracle.com> References: <20240817094800.776408-1-john.g.garry@oracle.com> X-ClientProxiedBy: MN2PR02CA0023.namprd02.prod.outlook.com (2603:10b6:208:fc::36) To DM6PR10MB4313.namprd10.prod.outlook.com (2603:10b6:5:212::20) Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR10MB4313:EE_|PH0PR10MB4758:EE_ X-MS-Office365-Filtering-Correlation-Id: fe48bc44-c381-43e3-2c93-08dcbea1bd2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 01ZlNN/hcKDhReRJZLH4c1cglA/Ghh6rfYaxSc1yocK4471vpF+M7nG7CaVZwWMeotq9K2D/kb000eU4yE/PH2dTQAVYcPlE6EftsMHqnAh/oRac75IB4Cp6MOOoq5WgUcxnM7jVFqyR6EjtoabJxtbeVhvNkP6J8qHWTkq7rN/S32CaFXKfiePJYpLdsqMD3BQBfVXLzGu51GOJJrCix3WEXQDfom68WRpw2swcO34g6shLV6kHADQBl0CAkp7X8JSPuRARPOKISrXkG4nt0DusQo7Gy82d/3blWG2mMR0OTLalDqIScmJFebtKGXlXz3JuLJgk4hC32aAl483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:;IPV:NLI;SFV:NSPM;H:DM6PR10MB4313.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fvuy0Dv/arA7NOFTR3iXcANs9D94oQsSl5EN9btDfhYYgLlMM0FvwkcJSniJksZArTWPrM74KZwFL4Ku1yP+jVJRgrWCatgWWGU6u1fxxvkwNLAkbLj8LJKFhd6PkjMiW9MgfNJwjcw2+khYULFBpZOtPDtnZUG8kIk3i9iDv1iPaUTyzl8p+O2JMYTsgMv6Egs/OXq/mA2YDvHj1wfe489QeOkEIYyDMTlxh56VtC6BxFaj2pSce0NLCBXJCZud7A7f4XYTjpq3tjeHSZLT3MJQRLhx+voNfh5T4tP27P+hETqXLIWdAJ0hnCMfHVdVvxYgzXGJREaswuKayfRzslJvKdxxMFtG6q+zK4uY7Zxn5eBUsnkoxG8cOaVo72QMUScqNMEc6oEp6QfuTH0yn6OwqzAMjD9UgdGTST0Ep4pCcrgjeRH7fhlfrT/RxtSSucqfcnSjX65E8MVVplsAaIhxC3vcYU/dF03xF7TupBkUtVzeGR2UZQrP2zsubRul20q4/4rRw2e+PMAuec+0J5lXGXK7/FPe6QJ8xFp6T1Z9e+N6s/97cHLhVC0vkRzKvdi49pLlUGKVQzo7TpCbGp7y+aUR2nPPAzifXcFebSLmbjj1Kth941QcSh3y97b/U/nO/a84SPhSgi5ZN6juAWaMsguid0XbX2ve+rxTLGzqAy3vY7DWwysyE9ZH7x1Aa+/QMzDAOuxHvJpVZEJb1z8ztsYQghG1gn1UJUjhdLmJJtSjZcb4TmKVVX1G7ArsCO3co0XhytO2BN8poTjsC7HcVtJ1dkuv8m1Ez8GyIp3Gns9MRQfJu7hJbbBx5aLoSqtwjlT6JeERScLe0t4tfm5UjOmULo85kaE88Znm9Qo7Gdu19usa0aasnFDIJD1S30vkgVcRpjGPCPH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c2B9948QmH7XRpOZw/qS2TeyiSNVMBH7lwUb5Y5QhsG7SmTZXM5Kv49rZFZTVjZegilk0kwuIfoJ1pEFWZlEj7QyQMBzHhSbS8lSF52SC8F0z8qQ5ehiET1goTB8Z5u+kKPDcmO+1uJ7lznXyTZqA5tTBOtJun9JM/9gvXtmm4wd4lxMV335Mo+tkgNqgNXf7NC/jqnV4yw/97R0rG8AENj1H+kH96tJRuqk3TFitDvB6VUy8kmOj0g671L+wI2KzY1YL0X20VgeJr6jrFGDJiMhZTQtQdPPLdpNhFRVrYNkLD/ZyIkRXzJE1mXjMEfxfYZz3edXR0Iy0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe48bc44-c381-43e3-2c93-08dcbea1bd2c X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB4313.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2024 09:48:25.4324 (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: kbpKJ6GzoIOt/JmMCXJXnNS/fJOogQwfl5ghXtppY5GNpM5E9IhTfECC644xvpOm06bsWNto0ai6QiHvyW2i/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4758 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-17_04,2024-08-16_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408170068 X-Proofpoint-ORIG-GUID: EP27VvkOVrsQN0No2GLXOroEKIZuq4Uq X-Proofpoint-GUID: EP27VvkOVrsQN0No2GLXOroEKIZuq4Uq Validate that an atomic write adheres to length/offset rules. Since we require extent alignment for atomic writes, this effectively also enforces that the BIO which iomap produces is aligned. For an IOCB with IOCB_ATOMIC set to get as far as xfs_file_dio_write(), FMODE_CAN_ATOMIC_WRITE will need to be set for the file; for this, FORCEALIGN and also ATOMICWRITES flags would also need to be set for the inode. Signed-off-by: John Garry --- fs/xfs/xfs_file.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 4cdc54dc9686..9b6530a4eb4a 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -684,9 +684,20 @@ xfs_file_dio_write( struct kiocb *iocb, struct iov_iter *from) { - struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp)); + struct inode *inode = file_inode(iocb->ki_filp); + struct xfs_inode *ip = XFS_I(inode); struct xfs_buftarg *target = xfs_inode_buftarg(ip); size_t count = iov_iter_count(from); + struct xfs_mount *mp = ip->i_mount; + + if (iocb->ki_flags & IOCB_ATOMIC) { + if (count < i_blocksize(inode)) + return -EINVAL; + if (count > XFS_FSB_TO_B(mp, ip->i_extsize)) + return -EINVAL; + if (!generic_atomic_write_valid(iocb, from)) + return -EINVAL; + } /* direct I/O must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask)