From: Liam Howlett <liam.howlett@oracle.com>
To: "maple-tree@lists.infradead.org" <maple-tree@lists.infradead.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Song Liu <songliubraving@fb.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
Matthew Wilcox <willy@infradead.org>,
Laurent Dufour <ldufour@linux.ibm.com>,
David Rientjes <rientjes@google.com>,
Axel Rasmussen <axelrasmussen@google.com>,
Suren Baghdasaryan <surenb@google.com>,
Vlastimil Babka <vbabka@suse.cz>, Rik van Riel <riel@surriel.com>,
Peter Zijlstra <peterz@infradead.org>,
Michel Lespinasse <michel@lespinasse.org>
Subject: Re: [PATCH 01/22] mm: Add vma_lookup()
Date: Fri, 21 May 2021 14:24:47 +0000 [thread overview]
Message-ID: <20210521142440.n6ejmeaxnxjus2to@revolver> (raw)
In-Reply-To: <20210521033232.dyams2dziycp4hv7@offworld>
* Davidlohr Bueso <dave@stgolabs.net> [210520 23:32]:
> On Mon, 10 May 2021, Liam Howlett wrote:
>
> > Many places in the kernel use find_vma() to get a vma and then check the
> > start address of the vma to ensure the next vma was not returned.
> >
> > Other places use the find_vma_intersection() call with add, addr + 1 as
> > the range; looking for just the vma at a specific address.
> >
> > The third use of find_vma() is by developers who do not know that the
> > function starts searching at the provided address upwards for the next
> > vma. This results in a bug that is often overlooked for a long time.
> >
> > Adding the new vma_lookup() function will allow for cleaner code by
> > removing the find_vma() calls which check limits, making
> > find_vma_intersection() calls of a single address to be shorter, and
> > potentially reduce the incorrect uses of find_vma().
> >
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> > ---
> > include/linux/mm.h | 18 ++++++++++++++++++
> > 1 file changed, 18 insertions(+)
> >
> > diff --git a/include/linux/mm.h b/include/linux/mm.h
> > index 25b9041f9925..5f2a15e702ff 100644
> > --- a/include/linux/mm.h
> > +++ b/include/linux/mm.h
> > @@ -2689,6 +2689,24 @@ static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * m
> > return vma;
> > }
>
> While at it can we clean up find_vma_intersection? I'm not particularly
> user/fan of checkpatch.pl, but this one is kind of ridiculous.
Agreed. This addition is worth re-spin. I will change the comment into
a kernel documentation style comment at the same time.
>
> Thanks,
> Davidlohr
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index c274f75efcf9..16eddedf783f 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2678,9 +2678,14 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
> extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
> struct vm_area_struct **pprev);
>
> -/* Look up the first VMA which intersects the interval start_addr..end_addr-1,
> - NULL if none. Assume start_addr < end_addr. */
> -static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
> +/*
> + * Look up the first VMA which intersects the interval start_addr..end_addr-1,
> + * NULL if none. Assume start_addr < end_addr.
> + */
> +static inline
> +struct vm_area_struct *find_vma_intersection(struct mm_struct * mm,
> + unsigned long start_addr,
> + unsigned long end_addr)
> {
> struct vm_area_struct * vma = find_vma(mm,start_addr);
next prev parent reply other threads:[~2021-05-21 14:25 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-10 16:58 [PATCH 00/21] " Liam Howlett
2021-05-10 16:58 ` [PATCH 03/22] arch/arc/kernel/troubleshoot: use vma_lookup() instead of find_vma() Liam Howlett
2021-05-10 16:58 ` [PATCH 01/22] mm: Add vma_lookup() Liam Howlett
2021-05-14 9:57 ` David Hildenbrand
2021-05-21 3:32 ` Davidlohr Bueso
2021-05-21 14:24 ` Liam Howlett [this message]
2021-05-10 16:58 ` [PATCH 02/22] drm/i915/selftests: Use vma_lookup() in __igt_mmap() Liam Howlett
2021-05-10 16:58 ` [PATCH 04/22] arch/arm64/kvm: Use vma_lookup() instead of find_vma_intersection() Liam Howlett
2021-05-10 16:58 ` [PATCH 05/22] arch/powerpc/kvm/book3s_hv_uvmem: " Liam Howlett
2021-05-10 16:58 ` [PATCH 06/22] arch/powerpc/kvm/book3s: Use vma_lookup() in kvmppc_hv_setup_htab_rma() Liam Howlett
2021-05-10 16:58 ` [PATCH 07/22] arch/mips/kernel/traps: Use vma_lookup() instead of find_vma() Liam Howlett
2021-05-10 16:58 ` [PATCH 09/22] x86/sgx: Use vma_lookup() in sgx_encl_find() Liam Howlett
2021-05-10 16:58 ` [PATCH 08/22] arch/m68k/kernel/sys_m68k: Use vma_lookup() in sys_cacheflush() Liam Howlett
2021-05-11 7:15 ` Geert Uytterhoeven
2021-05-10 16:58 ` [PATCH 10/22] virt/kvm: Use vma_lookup() instead of find_vma_intersection() Liam Howlett
2021-05-10 16:58 ` [PATCH 11/22] vfio: " Liam Howlett
2021-05-10 16:58 ` [PATCH 12/22] net/ipv5/tcp: Use vma_lookup() in tcp_zerocopy_receive() Liam Howlett
2021-05-10 16:58 ` [PATCH 13/22] drm/amdgpu: Use vma_lookup() in amdgpu_ttm_tt_get_user_pages() Liam Howlett
2021-05-10 16:58 ` [PATCH 14/22] media: videobuf2: Use vma_lookup() in get_vaddr_frames() Liam Howlett
2021-05-10 16:58 ` [PATCH 15/22] misc/sgi-gru/grufault: Use vma_lookup() in gru_find_vma() Liam Howlett
2021-05-10 16:58 ` [PATCH 16/22] kernel/events/uprobes: Use vma_lookup() in find_active_uprobe() Liam Howlett
2021-05-10 16:58 ` [PATCH 18/22] mm/ksm: Use vma_lookup() in find_mergeable_vma() Liam Howlett
2021-05-10 16:58 ` [PATCH 17/22] lib/test_hmm: Use vma_lookup() in dmirror_migrate() Liam Howlett
2021-05-10 16:58 ` [PATCH 19/22] mm/migrate: Use vma_lookup() in do_pages_stat_array() Liam Howlett
2021-05-10 16:58 ` [PATCH 20/22] mm/mremap: Use vma_lookup() in vma_to_resize() Liam Howlett
2021-05-21 3:47 ` Davidlohr Bueso
2021-05-21 14:27 ` Liam Howlett
2021-05-10 16:58 ` [PATCH 21/22] mm/memory.c: Use vma_lookup() in __access_remote_vm() Liam Howlett
2021-05-10 16:58 ` [PATCH 22/22] mm/mempolicy: " Liam Howlett
2021-05-17 17:28 ` [PATCH 00/21] mm: Add vma_lookup() Laurent Dufour
2021-05-21 4:20 ` Davidlohr Bueso
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=20210521142440.n6ejmeaxnxjus2to@revolver \
--to=liam.howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=ldufour@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maple-tree@lists.infradead.org \
--cc=michel@lespinasse.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=rientjes@google.com \
--cc=songliubraving@fb.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--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