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 X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1684C433B4 for ; Fri, 21 May 2021 03:32:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F1D66100A for ; Fri, 21 May 2021 03:32:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F1D66100A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=stgolabs.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E933494000F; Thu, 20 May 2021 23:32:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E43EF94000D; Thu, 20 May 2021 23:32:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE40D94000F; Thu, 20 May 2021 23:32:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 9A8D094000D for ; Thu, 20 May 2021 23:32:52 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 32C22D226 for ; Fri, 21 May 2021 03:32:52 +0000 (UTC) X-FDA: 78163816584.20.F03FABF Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf26.hostedemail.com (Postfix) with ESMTP id AB5C440B8CEC for ; Fri, 21 May 2021 03:32:50 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 12E64AB64; Fri, 21 May 2021 03:32:50 +0000 (UTC) Date: Thu, 20 May 2021 20:32:32 -0700 From: Davidlohr Bueso To: Liam Howlett Cc: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton , Song Liu , "Paul E . McKenney" , Matthew Wilcox , Laurent Dufour , David Rientjes , Axel Rasmussen , Suren Baghdasaryan , Vlastimil Babka , Rik van Riel , Peter Zijlstra , Michel Lespinasse Subject: Re: [PATCH 01/22] mm: Add vma_lookup() Message-ID: <20210521033232.dyams2dziycp4hv7@offworld> Mail-Followup-To: Liam Howlett , "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton , Song Liu , "Paul E . McKenney" , Matthew Wilcox , Laurent Dufour , David Rientjes , Axel Rasmussen , Suren Baghdasaryan , Vlastimil Babka , Rik van Riel , Peter Zijlstra , Michel Lespinasse References: <20210510165839.2692974-1-Liam.Howlett@Oracle.com> <20210510165839.2692974-2-Liam.Howlett@Oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210510165839.2692974-2-Liam.Howlett@Oracle.com> User-Agent: NeoMutt/20201120 Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=softfail (imf26.hostedemail.com: 195.135.220.15 is neither permitted nor denied by domain of dave@stgolabs.net) smtp.mailfrom=dave@stgolabs.net X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AB5C440B8CEC X-Stat-Signature: p4qcy4jpm84ksso9by9mehmzgaw1xrmp X-HE-Tag: 1621567970-766400 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: 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 >--- > 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. 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);