From: Jens Axboe <axboe@kernel.dk>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Miklos Szeredi <miklos@szeredi.hu>,
	David Howells <dhowells@redhat.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v2] fs: create kiocb_{start,end}_write() helpers
Date: Wed, 16 Aug 2023 13:13:31 -0600	[thread overview]
Message-ID: <e6948836-1d9d-4219-9a21-a2ab442a9a34@kernel.dk> (raw)
In-Reply-To: <CAOQ4uxggGRdhyRL15b_nVuf9PHejfXmF+auxY7HPkhJVYmsnCg@mail.gmail.com>
On 8/16/23 12:58 PM, Amir Goldstein wrote:
>>> diff --git a/fs/aio.c b/fs/aio.c
>>> index 77e33619de40..16fb3ac2093b 100644
>>> --- a/fs/aio.c
>>> +++ b/fs/aio.c
>>> @@ -1444,17 +1444,8 @@ static void aio_complete_rw(struct kiocb *kiocb, long res)
>>>       if (!list_empty_careful(&iocb->ki_list))
>>>               aio_remove_iocb(iocb);
>>>
>>> -     if (kiocb->ki_flags & IOCB_WRITE) {
>>> -             struct inode *inode = file_inode(kiocb->ki_filp);
>>> -
>>> -             /*
>>> -              * Tell lockdep we inherited freeze protection from submission
>>> -              * thread.
>>> -              */
>>> -             if (S_ISREG(inode->i_mode))
>>> -                     __sb_writers_acquired(inode->i_sb, SB_FREEZE_WRITE);
>>> -             file_end_write(kiocb->ki_filp);
>>> -     }
>>> +     if (kiocb->ki_flags & IOCB_WRITE)
>>> +             kiocb_end_write(kiocb);
>>
>> Can't we just call kiocb_end_write() here, it checks WRITE_STARTED
>> anyway? Not a big deal, and honestly I'd rather just get rid of
>> WRITE_STARTED if we're not using it like that. It doesn't serve much of
>> a purpose, if we're gating this one IOCB_WRITE anyway (which I do like
>> better than WRITE_STARTED). And it avoids writing to the kiocb at the
>> end too, which is a nice win.
>>
> 
> What I don't like about it is that kiocb_{start,end}_write() calls will
> not be balanced, so it is harder for a code reviewer to realize that the
> code is correct (as opposed to have excess end_write calls).
> That's the reason I had ISREG check inside the helpers in v1, so like
> file_{start,end}_write(), the calls will be balanced and easy to review.
If you just gate it on IOCB_WRITE and local IS_REG test, then it should
be balanced.
> I am not sure, but I think that getting rid of WRITE_STARTED will
> make the code more subtle, because right now, IOCB_WRITE is
> not set by kiocb_start_write() and many times it is set much sooner.
> So I'd rather keep the WRITE_STARTED flag for a more roust code
> if that's ok with you.
Adding random flags to protect against that is not a good idea imho. It
adds overhead and while it may seem like it's hardening, it's also then
just making it easier to misuse.
I would start with just adding the helpers, and having the callers gate
them with IOCB_WRITE && IS_REG like they do now.
>> index b2adee67f9b2..8e5d410a1be5 100644
>>> --- a/include/linux/fs.h
>>> +++ b/include/linux/fs.h
>>> @@ -338,6 +338,8 @@ enum rw_hint {
>>>  #define IOCB_NOIO            (1 << 20)
>>>  /* can use bio alloc cache */
>>>  #define IOCB_ALLOC_CACHE     (1 << 21)
>>> +/* file_start_write() was called */
>>> +#define IOCB_WRITE_STARTED   (1 << 22)
>>>
>>>  /* for use in trace events */
>>>  #define TRACE_IOCB_STRINGS \
>>> @@ -351,7 +353,8 @@ enum rw_hint {
>>>       { IOCB_WRITE,           "WRITE" }, \
>>>       { IOCB_WAITQ,           "WAITQ" }, \
>>>       { IOCB_NOIO,            "NOIO" }, \
>>> -     { IOCB_ALLOC_CACHE,     "ALLOC_CACHE" }
>>> +     { IOCB_ALLOC_CACHE,     "ALLOC_CACHE" }, \
>>> +     { IOCB_WRITE_STARTED,   "WRITE_STARTED" }
>>>
>>>  struct kiocb {
>>>       struct file             *ki_filp;
>>
>> These changes will conflict with other changes in linux-next that are
>> going upstream. I'd prefer to stage this one after those changes, once
>> we get to a version that looks good to everybody.
> 
> Changes coming to linux-next from your tree?
> I was basing my patches on Christian's vfs.all branch.
> Do you mean that you would like to stage this cleanup?
> It's fine by me.
From the xfs tree, if you look at linux-next you should see them. I
don't care who stages it, but I don't want to create needless merge
conflicts because people weren't aware of these conflicts.
-- 
Jens Axboe
next prev parent reply	other threads:[~2023-08-16 19:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16  8:54 [PATCH v2] fs: create kiocb_{start,end}_write() helpers Amir Goldstein
2023-08-16 15:01 ` Jan Kara
2023-08-16 15:28 ` Jens Axboe
2023-08-16 18:58   ` Amir Goldstein
2023-08-16 19:13     ` Jens Axboe [this message]
2023-08-17 13:18       ` Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=e6948836-1d9d-4219-9a21-a2ab442a9a34@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).