From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78315C3062E for ; Thu, 17 Aug 2023 14:48:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352236AbjHQOsT (ORCPT ); Thu, 17 Aug 2023 10:48:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352400AbjHQOsR (ORCPT ); Thu, 17 Aug 2023 10:48:17 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5200535AB for ; Thu, 17 Aug 2023 07:47:56 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3E59B1F37E; Thu, 17 Aug 2023 14:47:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1692283653; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7nVpWvK4Wyw4M6Q5ZsxplRUEC+QlgZmOtXOI84haljk=; b=wx/Qdm28p6+26DZkXoDTnnWK6IDbPlVNp9CM+8QFxE19xZh/dX5G+6yAJl7UxjJjxUmhrF S85YOj4HC2BEBpnhYMCB3wN+qbz6umREmvDOse9iFl2HMA3hMHTQYHVU9y+JAv5tsOlJ+e K3mb03Q0z+FJa/RCAZFxLMr6boScW60= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1692283653; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7nVpWvK4Wyw4M6Q5ZsxplRUEC+QlgZmOtXOI84haljk=; b=S5wX+0nLYeFUX/hG7nEwaEZfiADr9F+Mc/p6g8d7rJiIKh/Db8WMbJiV1+M8WFI4gdOpr/ h/8GYViVwoD902DA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 30A071392B; Thu, 17 Aug 2023 14:47:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iMXaCwUz3mRPMAAAMHmgww (envelope-from ); Thu, 17 Aug 2023 14:47:33 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id CE9DBA0769; Thu, 17 Aug 2023 16:47:32 +0200 (CEST) Date: Thu, 17 Aug 2023 16:47:32 +0200 From: Jan Kara To: Amir Goldstein Cc: Christian Brauner , Jan Kara , Jens Axboe , Miklos Szeredi , David Howells , Al Viro , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v3 3/7] fs: create kiocb_{start,end}_write() helpers Message-ID: <20230817144732.dyeu6e6c5a2m63fg@quack3> References: <20230817141337.1025891-1-amir73il@gmail.com> <20230817141337.1025891-4-amir73il@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230817141337.1025891-4-amir73il@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu 17-08-23 17:13:33, Amir Goldstein wrote: > aio, io_uring, cachefiles and overlayfs, all open code an ugly variant > of file_{start,end}_write() to silence lockdep warnings. > > Create helpers for this lockdep dance so we can use the helpers in all > the callers. > > Suggested-by: Jan Kara > Signed-off-by: Amir Goldstein Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > include/linux/fs.h | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/include/linux/fs.h b/include/linux/fs.h > index ced388aff51f..2548048a6e6c 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2579,6 +2579,42 @@ static inline void file_end_write(struct file *file) > sb_end_write(file_inode(file)->i_sb); > } > > +/** > + * kiocb_start_write - get write access to a superblock for async file io > + * @iocb: the io context we want to submit the write with > + * > + * This is a variant of sb_start_write() for async io submission. > + * Should be matched with a call to kiocb_end_write(). > + */ > +static inline void kiocb_start_write(struct kiocb *iocb) > +{ > + struct inode *inode = file_inode(iocb->ki_filp); > + > + sb_start_write(inode->i_sb); > + /* > + * Fool lockdep by telling it the lock got released so that it > + * doesn't complain about the held lock when we return to userspace. > + */ > + __sb_writers_release(inode->i_sb, SB_FREEZE_WRITE); > +} > + > +/** > + * kiocb_end_write - drop write access to a superblock after async file io > + * @iocb: the io context we sumbitted the write with > + * > + * Should be matched with a call to kiocb_start_write(). > + */ > +static inline void kiocb_end_write(struct kiocb *iocb) > +{ > + struct inode *inode = file_inode(iocb->ki_filp); > + > + /* > + * Tell lockdep we inherited freeze protection from submission thread. > + */ > + __sb_writers_acquired(inode->i_sb, SB_FREEZE_WRITE); > + sb_end_write(inode->i_sb); > +} > + > /* > * This is used for regular files where some users -- especially the > * currently executed binary in a process, previously handled via > -- > 2.34.1 > -- Jan Kara SUSE Labs, CR