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=-5.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 23D4FC433DB for ; Tue, 9 Feb 2021 17:19:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9162D64EC0 for ; Tue, 9 Feb 2021 17:19:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9162D64EC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F0D766B006E; Tue, 9 Feb 2021 12:19:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBD386B0070; Tue, 9 Feb 2021 12:19:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D86306B0071; Tue, 9 Feb 2021 12:19:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id C31076B006E for ; Tue, 9 Feb 2021 12:19:46 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8B6031856D0EA for ; Tue, 9 Feb 2021 17:19:46 +0000 (UTC) X-FDA: 77799391572.25.basin61_1113e9827609 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 5E43518525743 for ; Tue, 9 Feb 2021 17:19:46 +0000 (UTC) X-HE-Tag: basin61_1113e9827609 X-Filterd-Recvd-Size: 5608 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 17:19:45 +0000 (UTC) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 119HJFPW143009; Tue, 9 Feb 2021 12:19:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=6kpL+YmBtvFER70gmjnty/Gh6ETYB6a9EPU8SPCTbVA=; b=jXg4+H+6OdE37NUbajIWqKLbAEhB7nRqAUbcmCBGES+N02k6hnXjWycOdIiJL3y2OybZ w8Mpo7wUknPKAHhehB6BLBbLdJC0zxmUxJgKMfqvlRdxxCvkrtb6R4eKe8bBJb6X13uN bz5KcWWqYDmAYvC0yW5xIfyRdf6YjwCWhjFkqBvjdEy8mXdwwM4chQOjgHSmXKas8eHy n2+UiFPARqoiAB1yUFC8BBE5RolGe6bSkOMyf5gCLK2oa/266aMBqPFSc+DD0CDSG6OB AuWo7IRTvLvjVijL3VDfVMvFRrHWHVbyf7W2ov2fARXOJp4bsqBWvik/g88SqawQGBgx Yw== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 36kxkq85m1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Feb 2021 12:19:41 -0500 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 119Gv36T004444; Tue, 9 Feb 2021 17:19:38 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 36hjr8bmdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Feb 2021 17:19:38 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 119HJZIm38601150 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 9 Feb 2021 17:19:35 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D5B411C05C; Tue, 9 Feb 2021 17:19:35 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7242611C05B; Tue, 9 Feb 2021 17:19:35 +0000 (GMT) Received: from pomme.local (unknown [9.145.28.169]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 9 Feb 2021 17:19:35 +0000 (GMT) Subject: Re: synchronize_rcu in munmap? To: Matthew Wilcox , linux-mm@kvack.org Cc: "Liam R. Howlett" , Paul McKenney References: <20210208132643.GP308988@casper.infradead.org> <20210209142941.GY308988@casper.infradead.org> From: Laurent Dufour Message-ID: <17e3b4d0-8a16-75ba-e1c7-b678e4cf2089@linux.ibm.com> Date: Tue, 9 Feb 2021 18:19:35 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210209142941.GY308988@casper.infradead.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.737 definitions=2021-02-09_05:2021-02-09,2021-02-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 mlxscore=0 bulkscore=0 clxscore=1011 adultscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102090083 Content-Transfer-Encoding: quoted-printable 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 09/02/2021 =C3=A0 15:29, Matthew Wilcox a =C3=A9crit=C2=A0: > On Mon, Feb 08, 2021 at 01:26:43PM +0000, Matthew Wilcox wrote: >> Next problem: /proc/$pid/smaps calls walk_page_vma() which starts out = by >> saying: >> mmap_assert_locked(walk.mm); >> which made me realise that smaps is also going to walk the page tables= . >> So the page tables have to be pinned by the existence of the VMA. >> Which means the page tables must be freed by the same RCU callback tha= t >> frees the VMA. But doing that means that a task which calls mmap(); >> munmap(); mmap(); must avoid allocating the same address for the secon= d >> mmap (until the RCU grace period has elapsed), otherwise threads on >> other CPUs may see the stale PTEs instead of the new ones. >> >> Solution 1: Move the page table freeing into the RCU callback, call >> synchronize_rcu() in munmap(). >> >> Solution 2: Refcount the VMA and free the page tables on refcount >> dropping to zero. This doesn't actually work because the stale PTE >> problem still exists. >> >> Solution 3: When unmapping a VMA, instead of erasing the VMA from the >> maple tree, put a "dead" entry in its place. Once the RCU freeing and= the >> TLB shootdown has happened, erase the entry and it can then be allocat= ed. >> If we do that MAP_FIXED will have to synchronize_rcu() if it overlaps >> a dead entry. >=20 > Solution 4: RCU free the page table pages and teach pagewalk.c to > be RCU-safe. That means that it will have to use rcu_dereference() > or READ_ONCE to dereference (eg) pmdp, but also allows GUP-fast to run > under the rcu read lock instead of disabling interrupts. I might be wrong but my understanding is that the RCU window could not be= closed=20 on a CPU where IRQs are disabled. So in a first step GUP-fast might conti= nue to=20 disable interrupts to get safe walking the page directories.