From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE8D0C433EF for ; Thu, 23 Jun 2022 18:25:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EB3F8E0180; Thu, 23 Jun 2022 14:25:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79B8C8E0144; Thu, 23 Jun 2022 14:25:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6643D8E0180; Thu, 23 Jun 2022 14:25:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 577C78E0144 for ; Thu, 23 Jun 2022 14:25:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 867B2359A4 for ; Thu, 23 Jun 2022 18:25:36 +0000 (UTC) X-FDA: 79610328672.02.E9F318F Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf30.hostedemail.com (Postfix) with ESMTP id F2E1180028 for ; Thu, 23 Jun 2022 18:25:35 +0000 (UTC) Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 25NHune6016140 for ; Thu, 23 Jun 2022 11:25:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=wzl40ncu9+N8GznKN7zuVZtUu0h7x3PlOCjn2K//01I=; b=O+oAA287hMlBIkHI3WqhiMPVAPzXmevbwxYvC3V6smsqZKUfkzzNl5HEdFLGvuZvHrYF aZj3+x8pgfuWlFVPNLRP7e4Kf+7Y/RpJYL9G+8K08Yqg/Q8JcAr/Hrc4+v7kjOos4D/s zV9GRP9SahwLyQm5JNxDS88mUVaAQ6iTu+4= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net (PPS) with ESMTPS id 3gvqwxjeym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:25:10 -0700 Received: from twshared25107.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 23 Jun 2022 11:25:08 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 91F5C10C5DC64; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christoph Hellwig , Christian Brauner Subject: [RESEND PATCH v9 10/14] fs: Add async write file modification handling. Date: Thu, 23 Jun 2022 10:51:53 -0700 Message-ID: <20220623175157.1715274-11-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: Y1cGCvYkLYRMHoTEaQ9NJbj1TZ3GmDPI X-Proofpoint-GUID: Y1cGCvYkLYRMHoTEaQ9NJbj1TZ3GmDPI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656008736; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wzl40ncu9+N8GznKN7zuVZtUu0h7x3PlOCjn2K//01I=; b=7BaDHz5afvO1OEMuWsRSzhAzpVDdnw+MX3/fj2fk8F/QqqOZagN2EaoRS0AM6WYGeXPzb3 HzziCJ5bXUUfffetdTtkGGabdRZrF8UouJ8keh04ojWZqWf/e/MLEeQw/DTmJRjFj127Qc u/6z8QZUUgDJIE6rIlBGzT6xBceOwCA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=O+oAA287; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf30.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656008736; a=rsa-sha256; cv=none; b=MtN+wlDFfI3FHzH10WQiJxfMNVmdSNuFo0IotSDoAE0z74Tq/Ul4RlB079yRLhHTTowxw4 LhG7xlyu14EY2X2ZnFkbfBKXy0J86we2asjWqk3YGG+9/7osht89noqXU9FsRTmnduP975 oizroW5Mc0BH2Ngnov1BblCJqMYDBbY= X-Rspamd-Queue-Id: F2E1180028 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=O+oAA287; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf30.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: foa4bzf6rj8u3xxms5c4z56o6e5bwk1z X-HE-Tag: 1656008735-315154 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This adds a file_modified_async() function to return -EAGAIN if the request either requires to remove privileges or needs to update the file modification time. This is required for async buffered writes, so the request gets handled in the io worker of io-uring. Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara Reviewed-by: Christian Brauner (Microsoft) --- fs/inode.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- include/linux/fs.h | 1 + 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index ff726d99ecc7..259ebf438893 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2116,17 +2116,21 @@ int file_update_time(struct file *file) EXPORT_SYMBOL(file_update_time); =20 /** - * file_modified - handle mandated vfs changes when modifying a file + * file_modified_flags - handle mandated vfs changes when modifying a fi= le * @file: file that was modified + * @flags: kiocb flags * * When file has been modified ensure that special * file privileges are removed and time settings are updated. * + * If IOCB_NOWAIT is set, special file privileges will not be removed an= d + * time settings will not be updated. It will return -EAGAIN. + * * Context: Caller must hold the file's inode lock. * * Return: 0 on success, negative errno on failure. */ -int file_modified(struct file *file) +static int file_modified_flags(struct file *file, int flags) { int ret; struct inode *inode =3D file_inode(file); @@ -2136,7 +2140,7 @@ int file_modified(struct file *file) * Clear the security bits if the process is not being run by root. * This keeps people from modifying setuid and setgid binaries. */ - ret =3D __file_remove_privs(file, 0); + ret =3D __file_remove_privs(file, flags); if (ret) return ret; =20 @@ -2146,11 +2150,46 @@ int file_modified(struct file *file) ret =3D inode_needs_update_time(inode, &now); if (ret <=3D 0) return ret; + if (flags & IOCB_NOWAIT) + return -EAGAIN; =20 return __file_update_time(file, &now, ret); } + +/** + * file_modified - handle mandated vfs changes when modifying a file + * @file: file that was modified + * + * When file has been modified ensure that special + * file privileges are removed and time settings are updated. + * + * Context: Caller must hold the file's inode lock. + * + * Return: 0 on success, negative errno on failure. + */ +int file_modified(struct file *file) +{ + return file_modified_flags(file, 0); +} EXPORT_SYMBOL(file_modified); =20 +/** + * kiocb_modified - handle mandated vfs changes when modifying a file + * @iocb: iocb that was modified + * + * When file has been modified ensure that special + * file privileges are removed and time settings are updated. + * + * Context: Caller must hold the file's inode lock. + * + * Return: 0 on success, negative errno on failure. + */ +int kiocb_modified(struct kiocb *iocb) +{ + return file_modified_flags(iocb->ki_filp, iocb->ki_flags); +} +EXPORT_SYMBOL_GPL(kiocb_modified); + int inode_needs_sync(struct inode *inode) { if (IS_SYNC(inode)) diff --git a/include/linux/fs.h b/include/linux/fs.h index bc84847c201e..c0d99b5a166b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2390,6 +2390,7 @@ static inline void file_accessed(struct file *file) } =20 extern int file_modified(struct file *file); +int kiocb_modified(struct kiocb *iocb); =20 int sync_inode_metadata(struct inode *inode, int wait); =20 --=20 2.30.2