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 558C5ECAAD3 for ; Fri, 9 Sep 2022 14:38:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0DE86B0071; Fri, 9 Sep 2022 10:38:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D96786B0072; Fri, 9 Sep 2022 10:38:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0FE36B0073; Fri, 9 Sep 2022 10:38:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AD72E6B0071 for ; Fri, 9 Sep 2022 10:38:42 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 846A5C1388 for ; Fri, 9 Sep 2022 14:38:42 +0000 (UTC) X-FDA: 79892803284.19.6D3D7CC Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf24.hostedemail.com (Postfix) with ESMTP id E08311800AA for ; Fri, 9 Sep 2022 14:38:41 +0000 (UTC) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 289DIbb7018352; Fri, 9 Sep 2022 14:38:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=8CTwBYWOdFlP4FwLmxHtfRQS81v6onzfClpL7+y63HE=; b=bk0wG4ZLPuUWpg3aQ7l92xo9RfB3B5qwdidqVOXZp8vboS3GzzANaz7m4tpv0rMOikWi z+J1rCj6P7QdhAa7Yqj3x9psaPTagmngB02r82PnaW8ezOiaArAsxjK2m9N4fnZL2+g+ a/X8NThPe4tMRFrWwLzn/a/ZKuVEzYhQkuu0XGn0iiwJNKs8dGf1DdoafnNrSDMKUbXn Ixz5Qq7Gl9N/IrJC1wxvWiQoYy6gmkuacVI39CiJXd4ApcBhh2hRqNwKgZPGqAFxXnkv LfsUwh7P6OKfDSDA0qUlK86BXOs4EwbOrNNrPyh1hU0O+x+gFM3zpRZ+ykahbCRar9kp /g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jg5exm0c9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Sep 2022 14:38:34 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 289DOmT2020042; Fri, 9 Sep 2022 14:38:33 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jg5exm0bc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Sep 2022 14:38:33 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 289EM0XG006289; Fri, 9 Sep 2022 14:38:31 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03fra.de.ibm.com with ESMTP id 3jbxj8x16f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Sep 2022 14:38:31 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 289EcSPV40698192 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Sep 2022 14:38:28 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 818724203F; Fri, 9 Sep 2022 14:38:28 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 733AD42042; Fri, 9 Sep 2022 14:38:27 +0000 (GMT) Received: from [9.145.83.17] (unknown [9.145.83.17]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 9 Sep 2022 14:38:27 +0000 (GMT) Message-ID: <630714df-dec1-4a41-6af3-380181d11669@linux.ibm.com> Date: Fri, 9 Sep 2022 16:38:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [RFC PATCH RESEND 21/28] mm: introduce find_and_lock_anon_vma to be used from arch-specific code Content-Language: fr To: Suren Baghdasaryan , akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org References: <20220901173516.702122-1-surenb@google.com> <20220901173516.702122-22-surenb@google.com> From: Laurent Dufour In-Reply-To: <20220901173516.702122-22-surenb@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: IcRKhDOEa6Ts-ePGWWJKeMBqdv8Loc-W X-Proofpoint-GUID: 0Yk3VPJJRdSVQygJF41M58APoGFE1EH4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-09_08,2022-09-09_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=601 phishscore=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2209090051 ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=bk0wG4ZL; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf24.hostedemail.com: domain of ldufour@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=ldufour@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662734322; a=rsa-sha256; cv=none; b=IDGaDfG7+psN5Uz4bpIWW2SMA4pqLoJLxFI3ge1eGD2ww/vRou/asyaEb+86CiTKyTa2fv XxtUsMqXdPUE0DgaN4rors46ptXCPahAkQSyYWiD7L7n0gW06f+dRM1z3EHHVvcOi1DcDq y6ME+/khOBE1x7lKEkfttCIcNK5qW6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662734322; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=8CTwBYWOdFlP4FwLmxHtfRQS81v6onzfClpL7+y63HE=; b=kRqDJFAVuR9hC3aSdsYDpkNd6No4N7f/Bi8SA012ay18at3h/ncos8fH7fyo1ESzSNN+oL sAPTQF2gOzRNOzju38u/UUJil2QirbCw1G0HxhS9YlMBYLAFayl7MK9reCuxjHFWbhkQD1 0ApvrBMBAR9DEUK5MlZCJCvCYKYLXuY= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=bk0wG4ZL; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf24.hostedemail.com: domain of ldufour@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=ldufour@linux.ibm.com X-Stat-Signature: a1txyzhpc9jrtmxygieyuzquf6p49hio X-Rspamd-Queue-Id: E08311800AA X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1662734321-236864 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: Le 01/09/2022 à 19:35, Suren Baghdasaryan a écrit : > Introduce find_and_lock_anon_vma function to lookup and lock an anonymous > VMA during page fault handling. When VMA is not found, can't be locked > or changes after being locked, the function returns NULL. The lookup is > performed under RCU protection to prevent the found VMA from being > destroyed before the VMA lock is acquired. VMA lock statistics are > updated according to the results. > > Signed-off-by: Suren Baghdasaryan > --- > include/linux/mm.h | 3 +++ > mm/memory.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 48 insertions(+) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 7c3190eaabd7..a3cbaa7b9119 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -684,6 +684,9 @@ static inline void vma_assert_no_reader(struct vm_area_struct *vma) > vma); > } > > +struct vm_area_struct *find_and_lock_anon_vma(struct mm_struct *mm, > + unsigned long address); > + > #else /* CONFIG_PER_VMA_LOCK */ > > static inline void vma_init_lock(struct vm_area_struct *vma) {} > diff --git a/mm/memory.c b/mm/memory.c > index 29d2f49f922a..bf557f7056de 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5183,6 +5183,51 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, > } > EXPORT_SYMBOL_GPL(handle_mm_fault); > > +#ifdef CONFIG_PER_VMA_LOCK > +static inline struct vm_area_struct *find_vma_under_rcu(struct mm_struct *mm, > + unsigned long address) > +{ > + struct vm_area_struct *vma = __find_vma(mm, address); > + > + if (!vma || vma->vm_start > address) > + return NULL; > + > + if (!vma_is_anonymous(vma)) > + return NULL; > + It looks to me more natural to first check that the VMA is part of the RB tree before try read locking it. > + if (!vma_read_trylock(vma)) { > + count_vm_vma_lock_event(VMA_LOCK_ABORT); > + return NULL; > + } > + > + /* Check if the VMA got isolated after we found it */ > + if (RB_EMPTY_NODE(&vma->vm_rb)) { > + vma_read_unlock(vma); > + count_vm_vma_lock_event(VMA_LOCK_MISS); > + return NULL; > + } > + > + return vma; > +} > + > +/* > + * Lookup and lock and anonymous VMA. Returned VMA is guaranteed to be stable > + * and not isolated. If the VMA is not found of is being modified the function > + * returns NULL. > + */ > +struct vm_area_struct *find_and_lock_anon_vma(struct mm_struct *mm, > + unsigned long address) > +{ > + struct vm_area_struct *vma; > + > + rcu_read_lock(); > + vma = find_vma_under_rcu(mm, address); > + rcu_read_unlock(); > + > + return vma; > +} > +#endif /* CONFIG_PER_VMA_LOCK */ > + > #ifndef __PAGETABLE_P4D_FOLDED > /* > * Allocate p4d page table.