From patchwork Tue Aug 27 04:18:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 13778827 Received: from mx07-001d1705.pphosted.com (mx07-001d1705.pphosted.com [185.132.183.11]) (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 7442C1AAD7 for ; Tue, 27 Aug 2024 04:48:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.132.183.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724734104; cv=fail; b=AiJgBjCUCJeO7HbYbB3B3z2Ml17BcMefopi4P1nrAwpQnK7Y87hqECKzTFnzUDv+pgTI8vuhPro7X7zdy+A7EAvqqwsi0YIA7Q3LURtT303CoGcJ6DTmkrgyxme2G341+QCEhLdKPZ6kwlLk0+DtIzSSWPGK+0F9OQG+5MS8BL8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724734104; c=relaxed/simple; bh=6aA6WrCr4tCC67G0S7QO/zrCFLm+wBoOV9TS1TqLC9c=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=UtwEVRdfRJxY9bKT8apETKoRUAKUObefu3PdIZThpkuAfV4q1GHSH1uWD+yuytP+ycupejOZ4HrLAxGBHw2YrRZnuM4I/NbqB6epi0lvo+Hu7cvr2l8n+b/uuuJTx7ovq88Jm7cqkQV8WPMhzOuQPgbUG38+71+LzNVUS/Hd9Y0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b=XT1GKvc3; arc=fail smtp.client-ip=185.132.183.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="XT1GKvc3" Received: from pps.filterd (m0209327.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47R1G8R8029941; Tue, 27 Aug 2024 04:18:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=S1; bh=m1v1tESZ4/kpwQ/6BiHVRvrwIvUjD bUpM98ZL+mBWUE=; b=XT1GKvc3gli8a0sado7Fjx8vuVj1A2xItLUq0XG9Mci4F rbrzLSzuuttV/Ll1b0zLN11hkpUwnB9Ze7oI9DLmT21pfvz3L5loDojDTC+YYw40 fLi7ZgxBryNfWkxGvjf3nemzFQdz83a6kLChWEmLFiKux/yTlBgDb7xPegNPD/s0 ElksXJXv8n00dGJsj12bg4vhDPpBdKzDE7Lu/iFso/nCmnQkycGqq4F6J8nU1Sqt Z/z7csnI9C7OW88+juaep0OXbK4ZB8cFQ332KjRqD5fc67r+2GnScQCUULVaefG3 n3hdvGWqTjeXqVBUNdTnwF7EmVKuQ4ZP9zp+nOXPw== Received: from apc01-sg2-obe.outbound.protection.outlook.com (mail-sgaapc01lp2104.outbound.protection.outlook.com [104.47.26.104]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 4177jxa9u2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Aug 2024 04:18:48 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RAgVXzouVi/mJ2PFoF0jGscf/n65DhgdpJjJqQA/SYfOwh6NcDy1jNhgUap2lejapATfCD89Y2m2CWpHXQaoIsAba++adXG7zTuTDUjmhKZJV3DfiGvjTbKUynlRSZh1ijUvDr7LoF3dQpImAbKNyPdsiwFwASn+POVpOcsZwVyTrP5Q45LaxxBPdaxwOOUTdy3PBGUOPxDhBJpOQSe+nX8KwH1YOYOFTe5Oq6QikObrVvacuv5nSF4f2v4oWK754pR29jQpT1OJzvH3H1MZO/OGWKM871ihBkzXef4WBvNYR0c7E7xOJBDLhkLPXlJSs0hgZTHidPY8nYbKpVhRhA== 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=m1v1tESZ4/kpwQ/6BiHVRvrwIvUjDbUpM98ZL+mBWUE=; b=l6ZPjaRkHp/DyfkF8b1UNbtLaqG6KLJuqQea/p/M1/A6izLW59czquVMielyZdUufPwPjzDatmut1x/6mipJ292bzkkEwEkIRC39++0Y0vSE5Zfj0KB0YE+myQ1rNezmIorUmi1f2p85+AEWgH84Vzi1gY6s4WTRmcJ4AYSBv+lkHAXAKST0oND7LmrAS14/RRVzkQlOJeyvX7JPyc+cxrjKV2J31E8hLO2jTry6fR6M49iQTQENh7aaNkj9Gf1ltzT0FMIo/OoNUwQ1xECCtbyhmN0Ege3cingDqOPme1lkAAzO9B5DenRYT3VpB0GoIezD5lNVUErdCUXH+L8qVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from TY0PR04MB6328.apcprd04.prod.outlook.com (2603:1096:400:279::9) by JH0PR04MB7843.apcprd04.prod.outlook.com (2603:1096:990:9c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.25; Tue, 27 Aug 2024 04:18:40 +0000 Received: from TY0PR04MB6328.apcprd04.prod.outlook.com ([fe80::6bcb:d0e7:297b:8fa6]) by TY0PR04MB6328.apcprd04.prod.outlook.com ([fe80::6bcb:d0e7:297b:8fa6%4]) with mapi id 15.20.7897.021; Tue, 27 Aug 2024 04:18:39 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" , "Wataru.Aoyama@sony.com" Subject: [PATCH v4] exfat: move extend valid_size into ->page_mkwrite() Thread-Topic: [PATCH v4] exfat: move extend valid_size into ->page_mkwrite() Thread-Index: AQHa+DeaEwtjVafccE+dD770a4znkg== Date: Tue, 27 Aug 2024 04:18:39 +0000 Message-ID: Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: TY0PR04MB6328:EE_|JH0PR04MB7843:EE_ x-ms-office365-filtering-correlation-id: 00eaf480-d679-4dfa-a67d-08dcc64f53fd x-proofpoint-id: d8690225-876f-412f-87c6-a7cb45557a4c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230040|1800799024|366016|376014|38070700018; x-microsoft-antispam-message-info: =?iso-8859-1?q?sZLSjDCcFa47LBOrvBE/LFTzPD?= =?iso-8859-1?q?ky45y+8KdXn2zTfjaC71tNw/ko7OQBVaOYilhNiDyd5/+ryM4reVGzGs90TX?= =?iso-8859-1?q?MHeuoudRpSz4kJS3z4vREnWkbunleAAYCG4aip40GIBPmSo/9r9VbDYYr3NA?= =?iso-8859-1?q?AKa7AAjH9M/sV+8PiFNrU4X1Dc5j3yM6J9HmiYhIqO9vakeS3Y3RiQ2HClyR?= =?iso-8859-1?q?Z1r7ckbYw/VaxrgYkbuR5bogNtCGk736X4bmmOiUh/FPLee6ILzh0c2kAZ7H?= =?iso-8859-1?q?kkydPfw/gOOJ4wj4dfQjibR3wqcHW9c5pRfPUTnHYPQiHtlktIE8eMux/Xvc?= =?iso-8859-1?q?cpFkTnfQ5WpMp6pH8JDQ5XZq8SzWezzhik+jEAoBOCCCYNWLLcs93of/IBJN?= =?iso-8859-1?q?tEPmFSU90Rpzh5b8dbzisKdQC++ShJvPn230cFT1HPKbHSegs16alb0JGqAT?= =?iso-8859-1?q?/SGxrZt+BXsk6x/vpStfSBbVb+KHRBs3njRnZBKnwygdi9YwuXRMNxN2UHDB?= =?iso-8859-1?q?cDF7NPLpQRKDyr6H3ZPRYG4OIBs4MghBk/4A+3h7xcnqGA32NMPuJjMwh23h?= =?iso-8859-1?q?yktIeLEpR3A5zeq3l9bmxyfJlpkwma1JhGRo2AYwNpUvn3oe3wi7cZX/gjm0?= =?iso-8859-1?q?lHjNMsCfZDuiInRRTtlx3EnZQEAxtM4/6SpEkflYYziNLvCTxxKvdwZUnKPJ?= =?iso-8859-1?q?N1grr4XvUNpje2kCZ5VYaXNY9WoykiMYkicBozyhWjE/Vs3phIVUVyXTmmWP?= =?iso-8859-1?q?Luczgag999V1m/hXK59gEwV0ncdH2GKmUuzpPc9uIXI8nMm9H1Mx8dNYiEDW?= =?iso-8859-1?q?8ouVizQIgb5/2hsQ8P9jr+BfG4IGgs/iBGJelb08bpA1WRpxwNbFLXNAiMR1?= =?iso-8859-1?q?OLXzCj8IgHj/UBrPaFzcq2nvluDqxSrNqJQaxp50iH/W7u4AsXAeD7rFR6pN?= =?iso-8859-1?q?vFqEz12aAo9TINVrSw71790oVu6tZA73l+Nep5/reZcDcRuwRtVrhMAcEnkR?= =?iso-8859-1?q?qTFOYUOasy8dldl8KB188au+hiFyRyw1jkOkJ+bfXcCQTj9Zgbh8Fom1vMc4?= =?iso-8859-1?q?xaLTKwFfVW/2jNJLLaJlzVIl5JVAA5GinBQJCWadhipfczdpP+64dPVbc9lm?= =?iso-8859-1?q?OjdRJNZQrO9BouW8fKMzNB/1MjufgusE+8thePAvb6i3hYwHFggSuvBC0Q3n?= =?iso-8859-1?q?XM165SwBZo47LxZEYZL6q/x+/TA4xxkjswk6uvSIl7dx6K7jfIjJUlOA27v+?= =?iso-8859-1?q?5Haht36be0Dg264MLd5HVukjUQgyssPXmQCMNdVqW1Oh4NmvAWheHanEkM0I?= =?iso-8859-1?q?etyuTGFih4Xq3AB9Qu5Zcgf5UkfWVoftET3sil6FPaIA9DMhcKBziKGM1b2q?= =?iso-8859-1?q?OnlverP+e7QVWLZWhRb73x4e6g6NCtFTAFz1KeHzm6suCQDtgw3qcHE64++M?= =?iso-8859-1?q?ELO1uwIq/djyDIdfekS4oQPg=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TY0PR04MB6328.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(38070700018);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?UXalRdjEvF7BxUMWPLUsG10?= =?iso-8859-1?q?5gc5wqCHZwq+hCIUfFw8fgTKbA5aeRyw7c7qDG59XRYdJS4JFGaG/SmN19Xv?= =?iso-8859-1?q?jFzagS15wJUD/HI1j1LWtOf4rqqg98QRERs1Nyv9jTIvGlKPcI5021IC3YE2?= =?iso-8859-1?q?CyKkxIsf84YVnqDPL//GEZZjndq+s9LdNOwjaAyzVxM9GirceO3ZfPnOaPZI?= =?iso-8859-1?q?Wokl0KPIIvRe/VdcpQyaRDS5ZUsOd4Jh9X1urBIsKLsNJMlVezOJRblrHPUB?= =?iso-8859-1?q?6LiWvrpxLrdWT0I4dr0Dr5Y76R5ps42Zk60/4qoJQfW/NMH4c2oYrtnbHvyv?= =?iso-8859-1?q?VgT8Gi8rcNs06BHXLYHjJyIuHf1xCG0jETEpeER+pt5WDKETV55F7eCaYunb?= =?iso-8859-1?q?VjgiZ0mt1I08on9TubhgpjiEnd6m2C6ZHNzaV4+80ANuIlSx2tzJwjoQaM8b?= =?iso-8859-1?q?emvG6Ww4YqICsViZIEQEH7BZ+FLBLh05RTJqX+km5tCmYEamyJX0h3yOqtv7?= =?iso-8859-1?q?zREts3uj3vbSOfdAn1P1mqMqc4xKszwKLwPFlxqfrYf8JKiAHuRO3i+TlpYP?= =?iso-8859-1?q?Wl8/x0TN2paDO0fFh3JlMO4/wbXeoDrvfP5lhyXJi+xmnQavEi18QXPWqX/T?= =?iso-8859-1?q?WQO3HUgaYskFNU4XQ8kkEDph/QrDr1sunIDuecE1n2jfUYmHxffUF4DbIX47?= =?iso-8859-1?q?nR4pBVYI+oB3Xc42KvyelsBuanl7unYha2Hkx1z/gkdNWr6TjdOLQVIQKYz9?= =?iso-8859-1?q?7RDIi/Yu44W2DYfExtFXTbtEw22G6fm464hsOxt07zFW/tyJ8kBVk2eXNBax?= =?iso-8859-1?q?tV8qQLZ5p60uqRDVG6jEbABAm96n800XFFqF30p4477qDURyIqP4sC6ht1z8?= =?iso-8859-1?q?NHURHaf7b1Qf/jfEbMVql29n7K361QevKr7u8GjIwRE1TN7CzoduerP9x988?= =?iso-8859-1?q?jfJnETFRGHotoJWoqNFazMOqYq7QPvtqgLYEQaALqyWYphVnvsDq41A71ZaG?= =?iso-8859-1?q?A7yHlDMYzv5eRBWowVHHyr6+FCtGIxJNu+4dN2Y6Kp22y/AL3oYoS/keX4Im?= =?iso-8859-1?q?N3t/CXHcqck381IIUGUCVKLeEDogCxhxLCXrtdwSPvjYi3W+NkLr2aQxF8Xa?= =?iso-8859-1?q?ObTqVcu6b4Ccl508vCKZvDcCLezIIuF7c1TYjEWDLW7wzb53LApv6/LIboMF?= =?iso-8859-1?q?BlO31oKGAzctV0qG0koGTUB3uOKnR5RVGwlw/RHF3TIQB7p/rW1OiZI8OKI+?= =?iso-8859-1?q?HaQC2eCe1aimLMq4I3Lgm3Mc0IK31dXg/nflPW4FJqncMcut1qVT1TIJNybT?= =?iso-8859-1?q?AmGBWE/rWNQS9o6QNMnsJ1oc9Z3wbc87+I/vwA64OSs/1aTCCAiW1gs207Vw?= =?iso-8859-1?q?1cr8pCn5LCD7RM9/77Fd0b/5IoHa22xXr3/wexDf6f38jq+qW9jgVwAiRE6y?= =?iso-8859-1?q?HeR5vYfCsN6xwWZc+z8p+q2Cm1487r32zehi4UXPAJni4IFzmhYZNPA0F16A?= =?iso-8859-1?q?nXWT+1lzDPNfkOs/JJ+MPGLj0R/xWT9ky5x54/PX2E/WWJ7epTbgS4GvSy7x?= =?iso-8859-1?q?ukw0t7v2LLmt6eOheCz9ZnUlqp+ouVgmQdJreeg6EHff6ZgmcQqyXZRF6ViP?= =?iso-8859-1?q?gfZ5HGbzSKVTyuasgHsEng9D0+j3bHruUJ5ohFHLloMy1A8X4dCUMA/3a09M?= =?iso-8859-1?q?=3D?= Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: pQcDWOQZQgc2PZZeDfySuy7je/FA29SsK5s70hQY2e3Pqw2DDCisgu6wvrvymxh6RhsBQeOYAqoTiBzNT91aNLuNbU+KiCTz8Qw0PNetAaIvADOMu0O1pbSYVTxHIQ0s7m09LNgyhnpyTDoHc2p7BQxuPORAA1F/W/1YhdqUj2sJKQtiuwlLgUiUylDOFCMl2hf7inB3JpyLz+0NJDrLN+Mqy1m7v4J9LBMlJQIr4d+N3Mjz/UEYU09L0NBSgMte9cyR4h9GFjGrsBxrmcvCvGHpAsJ+4QaGXa9QneZ2fYSBAKj6QqaMiVgzJ/przgnSl2bDcoQhuKDrofjluE5OIay5cEb7TtzeFXNDtsiqJftbjgNHYLtR3UQl4/zQ5GZhyqEyAo7VFozggIN+dpefygFrGX8ox1fYb72qRJmjeT5z+/hG0hpY2HJ1Rg+gI0eM17lNGQUrtVndR4IDDSkru7PreW40E+L41ECOA+HwIp27viehe03jUiaYCejqDtSo4VJoBHU40ruNfXujacnldF8rdJFifa9pbQ3Wdmc8OW+RwAMCFy6WzviAjzHx3A/DqCO9JI0tpR1Gsr3I4I11jAKzDBIdcHpi3xJuBQy06QATss1B3du/4t6uIYItXx9Z X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TY0PR04MB6328.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00eaf480-d679-4dfa-a67d-08dcc64f53fd X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Aug 2024 04:18:39.3331 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SpPMHCNI7NNTuIRSTMzZiXSHPsAWRYCDySjalWDetrt8lIQgq2DHaOBjtvMFGywISUKSdgVH2eTctJcnIMI62A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR04MB7843 X-Proofpoint-GUID: BcIyu9oxhdsA60ePNay-sIjrgM8Mu7Z0 X-Proofpoint-ORIG-GUID: BcIyu9oxhdsA60ePNay-sIjrgM8Mu7Z0 X-Sony-Outbound-GUID: BcIyu9oxhdsA60ePNay-sIjrgM8Mu7Z0 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-27_02,2024-08-26_01,2024-05-17_01 It is not a good way to extend valid_size to the end of the mmap area by writing zeros in mmap. Because after calling mmap, no data may be written, or only a small amount of data may be written to the head of the mmap area. This commit moves extending valid_size to exfat_page_mkwrite(). In exfat_page_mkwrite() only extend valid_size to the starting position of new data writing, which reduces unnecessary writing of zeros. If the block is not mapped and is marked as new after being mapped for writing, block_write_begin() will zero the page cache corresponding to the block, so there is no need to call zero_user_segment() in exfat_file_zeroed_range(). And after moving extending valid_size to exfat_page_mkwrite(), the data written by mmap will be copied to the page cache but the page cache may be not mapped to the disk. Calling zero_user_segment() will cause the data written by mmap to be cleared. So this commit removes calling zero_user_segment() from exfat_file_zeroed_range() and renames exfat_file_zeroed_range() to exfat_extend_valid_size(). Signed-off-by: Yuezhang Mo --- Changes for v2: - Remove a unnecessary check from exfat_file_mmap() Changes for v3: - Fix the potential deadlock - Change to use ->valid_size to determine whether exfat_block_page_mkwrite() needs to be called Changes for v4: - Use exfat_extend_valid_size() to extend ->valid_size to the end of mwrite fs/exfat/file.c | 70 +++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 0bee0c1efbc2..1547c7644882 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -532,32 +532,32 @@ int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync) return blkdev_issue_flush(inode->i_sb->s_bdev); } -static int exfat_file_zeroed_range(struct file *file, loff_t start, loff_t end) +static int exfat_extend_valid_size(struct file *file, loff_t new_valid_size) { int err; + loff_t pos; struct inode *inode = file_inode(file); + struct exfat_inode_info *ei = EXFAT_I(inode); struct address_space *mapping = inode->i_mapping; const struct address_space_operations *ops = mapping->a_ops; - while (start < end) { - u32 zerofrom, len; + pos = ei->valid_size; + while (pos < new_valid_size) { + u32 len; struct page *page = NULL; - zerofrom = start & (PAGE_SIZE - 1); - len = PAGE_SIZE - zerofrom; - if (start + len > end) - len = end - start; + len = PAGE_SIZE - (pos & (PAGE_SIZE - 1)); + if (pos + len > new_valid_size) + len = new_valid_size - pos; - err = ops->write_begin(file, mapping, start, len, &page, NULL); + err = ops->write_begin(file, mapping, pos, len, &page, NULL); if (err) goto out; - zero_user_segment(page, zerofrom, zerofrom + len); - - err = ops->write_end(file, mapping, start, len, len, page, NULL); + err = ops->write_end(file, mapping, pos, len, len, page, NULL); if (err < 0) goto out; - start += len; + pos += len; balance_dirty_pages_ratelimited(mapping); cond_resched(); @@ -585,7 +585,7 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter) goto unlock; if (pos > valid_size) { - ret = exfat_file_zeroed_range(file, valid_size, pos); + ret = exfat_extend_valid_size(file, pos); if (ret < 0 && ret != -ENOSPC) { exfat_err(inode->i_sb, "write: fail to zero from %llu to %llu(%zd)", @@ -619,26 +619,46 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter) return ret; } -static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma) +static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf) { - int ret; + int err; + struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; struct inode *inode = file_inode(file); struct exfat_inode_info *ei = EXFAT_I(inode); - loff_t start = ((loff_t)vma->vm_pgoff << PAGE_SHIFT); - loff_t end = min_t(loff_t, i_size_read(inode), + loff_t start, end; + + if (!inode_trylock(inode)) + return VM_FAULT_RETRY; + + start = ((loff_t)vma->vm_pgoff << PAGE_SHIFT); + end = min_t(loff_t, i_size_read(inode), start + vma->vm_end - vma->vm_start); - if ((vma->vm_flags & VM_WRITE) && ei->valid_size < end) { - ret = exfat_file_zeroed_range(file, ei->valid_size, end); - if (ret < 0) { - exfat_err(inode->i_sb, - "mmap: fail to zero from %llu to %llu(%d)", - start, end, ret); - return ret; + if (ei->valid_size < end) { + err = exfat_extend_valid_size(file, end); + if (err < 0) { + inode_unlock(inode); + return vmf_fs_error(err); } } - return generic_file_mmap(file, vma); + inode_unlock(inode); + + return filemap_page_mkwrite(vmf); +} + +static const struct vm_operations_struct exfat_file_vm_ops = { + .fault = filemap_fault, + .map_pages = filemap_map_pages, + .page_mkwrite = exfat_page_mkwrite, +}; + +static int exfat_file_mmap(struct file *file, struct vm_area_struct *vma) +{ + file_accessed(file); + vma->vm_ops = &exfat_file_vm_ops; + return 0; } const struct file_operations exfat_file_operations = {