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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F36AC433F5 for ; Wed, 15 Dec 2021 16:40:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC86D6B0071; Wed, 15 Dec 2021 11:40:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A779F6B0073; Wed, 15 Dec 2021 11:40:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F1336B0074; Wed, 15 Dec 2021 11:40:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id 819946B0071 for ; Wed, 15 Dec 2021 11:40:18 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 36EB7180D32E9 for ; Wed, 15 Dec 2021 16:40:08 +0000 (UTC) X-FDA: 78920590896.12.E7D26AC Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf25.hostedemail.com (Postfix) with ESMTP id 39050A0014 for ; Wed, 15 Dec 2021 16:40:03 +0000 (UTC) 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-out1.suse.de (Postfix) with ESMTPS id 3843A212BD; Wed, 15 Dec 2021 16:40:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1639586406; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PR/MemBldbTR728L096igmJMG3fo/uDTHlayL6mBYe4=; b=GQBBxdmBohS+o4ZBWp2/gqq4lzHNiZVSy1JPMq7MDWlpGnyALVbQFCf6utnQfj5mKLSQRA v/GHxV0ypGS2TAVlVA+VGjN0iSqtbbhAqWNetEInSPhdzxk6Wg6KAjHs7wCNCx2ILVT7QP sHkFEQZFJUayuDJ9mKcV/vyROUFBYSs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1639586406; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PR/MemBldbTR728L096igmJMG3fo/uDTHlayL6mBYe4=; b=nUwFhiF2wk6jrKHkh37AqVjYosXXTLnHXPQxO8djKhM2ieN2aTJtfUGmu/9CqIa2u0izfo xALB7V3InBlRjQCA== 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 DD51913B75; Wed, 15 Dec 2021 16:40:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Vj1KNWUaumGdJgAAMHmgww (envelope-from ); Wed, 15 Dec 2021 16:40:05 +0000 Message-ID: <92ef4cae-ccfb-d952-6b36-71036329e8da@suse.cz> Date: Wed, 15 Dec 2021 17:40:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v4 10/66] mm/mmap: Use the maple tree for find_vma_prev() instead of the rbtree Content-Language: en-US To: Liam Howlett , "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton Cc: Song Liu , Davidlohr Bueso , "Paul E . McKenney" , Matthew Wilcox , Laurent Dufour , David Rientjes , Axel Rasmussen , Suren Baghdasaryan , Rik van Riel , Peter Zijlstra , Michel Lespinasse , Jerome Glisse , Minchan Kim , Joel Fernandes , Rom Lemarchand References: <20211201142918.921493-1-Liam.Howlett@oracle.com> <20211201142918.921493-11-Liam.Howlett@oracle.com> From: Vlastimil Babka In-Reply-To: <20211201142918.921493-11-Liam.Howlett@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 39050A0014 X-Stat-Signature: cuydor4q8mhwzxrszed1jswmk4wa1tuy Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=GQBBxdmB; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nUwFhiF2; dmarc=none; spf=pass (imf25.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspamd-Server: rspam11 X-HE-Tag: 1639586403-362338 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 12/1/21 15:29, Liam Howlett wrote: > From: "Liam R. Howlett" > > Use the maple tree's advanced API and a maple state to walk the tree > for the entry at the address of the next vma, then use the maple state > to walk back one entry to find the previous entry. > > Add kernel documentation comments for this API. Additional note: the previous patch for find_vma() mentioned "Using the maple tree interface mt_find() will handle the RCU locking" while find_vma_prev() uses the advanced maple tree API, thus IIUC without RCU locking, and doesn't add its own. This can easily result in a bug, especially if the documentation comments don't mention it at all? > Signed-off-by: Liam R. Howlett > Signed-off-by: Matthew Wilcox (Oracle) > --- > mm/mmap.c | 24 ++++++++++++++---------- > 1 file changed, 14 insertions(+), 10 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index 6a7502f74190..8425ab573770 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -2454,23 +2454,27 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr) > } > EXPORT_SYMBOL(find_vma); > > -/* > - * Same as find_vma, but also return a pointer to the previous VMA in *pprev. > +/** > + * find_vma_prev() - Find the VMA for a given address, or the next vma and > + * set %pprev to the previous VMA, if any. > + * @mm: The mm_struct to check > + * @addr: The address > + * @pprev: The pointer to set to the previous VMA > + * > + * Returns: The VMA associated with @addr, or the next vma. > + * May return %NULL in the case of no vma at addr or above. > */ > struct vm_area_struct * > find_vma_prev(struct mm_struct *mm, unsigned long addr, > struct vm_area_struct **pprev) > { > struct vm_area_struct *vma; > + MA_STATE(mas, &mm->mm_mt, addr, addr); > > - vma = find_vma(mm, addr); > - if (vma) { > - *pprev = vma->vm_prev; > - } else { > - struct rb_node *rb_node = rb_last(&mm->mm_rb); > - > - *pprev = rb_node ? rb_entry(rb_node, struct vm_area_struct, vm_rb) : NULL; > - } > + vma = mas_walk(&mas); > + *pprev = mas_prev(&mas, 0); > + if (!vma) > + vma = mas_next(&mas, ULONG_MAX); > return vma; > } >