From: Lorenzo Stoakes <lstoakes@gmail.com>
To: David Hildenbrand <david@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <bhe@redhat.com>, Uladzislau Rezki <urezki@gmail.com>,
Matthew Wilcox <willy@infradead.org>,
Liu Shixin <liushixin2@huawei.com>, Jiri Olsa <jolsa@kernel.org>,
Jens Axboe <axboe@kernel.dk>,
Alexander Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH v4 4/4] mm: vmalloc: convert vread() to vread_iter()
Date: Wed, 22 Mar 2023 11:31:47 +0000 [thread overview]
Message-ID: <fe8f9909-332f-41c3-b672-a352cc6218d7@lucifer.local> (raw)
In-Reply-To: <8ba0360e-57eb-93b0-3ae6-612f6b371bff@redhat.com>
On Wed, Mar 22, 2023 at 12:18:08PM +0100, David Hildenbrand wrote:
> On 21.03.23 21:54, Lorenzo Stoakes wrote:
> > Having previously laid the foundation for converting vread() to an iterator
> > function, pull the trigger and do so.
> >
> > This patch attempts to provide minimal refactoring and to reflect the
> > existing logic as best we can, for example we continue to zero portions of
> > memory not read, as before.
> >
> > Overall, there should be no functional difference other than a performance
> > improvement in /proc/kcore access to vmalloc regions.
> >
> > Now we have eliminated the need for a bounce buffer in read_kcore_iter(),
> > we dispense with it. We need to ensure userland pages are faulted in before
> > proceeding, as we take spin locks.
> >
> > Additionally, we must account for the fact that at any point a copy may
> > fail if this happens, we exit indicating fewer bytes retrieved than
> > expected.
> >
> > Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
> > ---
> > fs/proc/kcore.c | 26 ++---
> > include/linux/vmalloc.h | 3 +-
> > mm/nommu.c | 10 +-
> > mm/vmalloc.c | 234 +++++++++++++++++++++++++---------------
> > 4 files changed, 160 insertions(+), 113 deletions(-)
> >
> > diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> > index 25e0eeb8d498..221e16f75ba5 100644
> > --- a/fs/proc/kcore.c
> > +++ b/fs/proc/kcore.c
> > @@ -307,13 +307,9 @@ static void append_kcore_note(char *notes, size_t *i, const char *name,
> > *i = ALIGN(*i + descsz, 4);
> > }
> > -static ssize_t
> > -read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
> > +static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
> > {
> > - struct file *file = iocb->ki_filp;
> > - char *buf = file->private_data;
> > loff_t *ppos = &iocb->ki_pos;
> > -
> > size_t phdrs_offset, notes_offset, data_offset;
> > size_t page_offline_frozen = 1;
> > size_t phdrs_len, notes_len;
> > @@ -507,9 +503,12 @@ read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
> > switch (m->type) {
> > case KCORE_VMALLOC:
> > - vread(buf, (char *)start, tsz);
> > - /* we have to zero-fill user buffer even if no read */
> > - if (copy_to_iter(buf, tsz, iter) != tsz) {
> > + /*
> > + * Make sure user pages are faulted in as we acquire
> > + * spinlocks in vread_iter().
> > + */
> > + if (fault_in_iov_iter_writeable(iter, tsz) ||
> > + vread_iter(iter, (char *)start, tsz) != tsz) {
> > ret = -EFAULT;
> > goto out;
> > }
>
> What if we race with swapout after faulting the pages in? Or some other
> mechanism to write-protect the user space pages?
>
> Also, "This is primarily useful when we already know that some or all of the
> pages in @i aren't in memory". This order of events might slow down things
> quite a bit if I am not wrong.
>
>
> Wouldn't you want to have something like:
>
> while (vread_iter(iter, (char *)start, tsz) != tsz) {
> if (fault_in_iov_iter_writeable(iter, tsz)) {
> ret = -EFAULT;
> goto out;
> }
> }
>
> Or am I missing something?
>
Indeed, I was thinking of this as:-
- prefault
- try (possibly fail if race) copy operation
However it does make more sense, and makes it explicit that it's an attempt that
might fail requiring a fault-in in the while form.
I think the upcoming change to explicitly make the iter function
copy_folio_to_iter_nofault() makes it clear from end-to-end what is being done -
we mustn't fault (spinlocks held) and if a fault would occur we error out, if we
error out try faulting in, if this fails then abort.
I will fixup in respin.
> --
> Thanks,
>
> David / dhildenb
>
next prev parent reply other threads:[~2023-03-22 11:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 20:54 [PATCH v4 0/4] convert read_kcore(), vread() to use iterators Lorenzo Stoakes
2023-03-21 20:54 ` [PATCH v4 1/4] fs/proc/kcore: avoid bounce buffer for ktext data Lorenzo Stoakes
2023-03-21 20:54 ` [PATCH v4 2/4] fs/proc/kcore: convert read_kcore() to read_kcore_iter() Lorenzo Stoakes
2023-03-22 1:15 ` Baoquan He
2023-03-22 6:17 ` Lorenzo Stoakes
2023-03-22 11:12 ` David Hildenbrand
2023-03-21 20:54 ` [PATCH v4 3/4] iov_iter: add copy_page_to_iter_atomic() Lorenzo Stoakes
2023-03-22 10:17 ` Baoquan He
2023-03-22 10:32 ` Lorenzo Stoakes
2023-03-22 11:06 ` Lorenzo Stoakes
2023-03-22 13:21 ` Baoquan He
2023-03-22 13:08 ` Baoquan He
2023-03-21 20:54 ` [PATCH v4 4/4] mm: vmalloc: convert vread() to vread_iter() Lorenzo Stoakes
2023-03-22 11:18 ` David Hildenbrand
2023-03-22 11:31 ` Lorenzo Stoakes [this message]
2023-03-22 12:55 ` Baoquan He
2023-03-22 13:43 ` Lorenzo Stoakes
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=fe8f9909-332f-41c3-b672-a352cc6218d7@lucifer.local \
--to=lstoakes@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bhe@redhat.com \
--cc=david@redhat.com \
--cc=jolsa@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liushixin2@huawei.com \
--cc=urezki@gmail.com \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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