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 9AFCCC433EF for ; Mon, 7 Feb 2022 03:35:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D60746B0072; Sun, 6 Feb 2022 22:35:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D0FAE6B0073; Sun, 6 Feb 2022 22:35:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C25906B0074; Sun, 6 Feb 2022 22:35:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id B40C16B0072 for ; Sun, 6 Feb 2022 22:35:33 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 672CB181DF761 for ; Mon, 7 Feb 2022 03:35:33 +0000 (UTC) X-FDA: 79114568946.18.4D3E1CD Received: from r3-19.sinamail.sina.com.cn (r3-19.sinamail.sina.com.cn [202.108.3.19]) by imf19.hostedemail.com (Postfix) with SMTP id 9F90B1A0004 for ; Mon, 7 Feb 2022 03:35:31 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.61.131]) by sina.com (172.16.97.35) with ESMTP id 6200936C0001FDA6; Mon, 7 Feb 2022 11:35:10 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 70085015073464 From: Hillf Danton To: Hugh Dickins Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 07/13] mm/munlock: mlock_pte_range() when mlocking or munlocking Date: Mon, 7 Feb 2022 11:35:18 +0800 Message-Id: <20220207033518.2602-1-hdanton@sina.com> In-Reply-To: <8bc3ee8c-7f1-d812-7f22-4f9f6d436bc@google.com> References: <8e4356d-9622-a7f0-b2c-f116b5f2efea@google.com> MIME-Version: 1.0 X-Stat-Signature: eo94ea4f7t8o6n44cnd3boejzycumgaa X-Rspam-User: nil Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.19 as permitted sender) smtp.mailfrom=hdanton@sina.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9F90B1A0004 X-HE-Tag: 1644204931-477004 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: On Sun, 6 Feb 2022 13:42:09 -0800 (PST) Hugh Dickins wrote: > +static void mlock_vma_pages_range(struct vm_area_struct *vma, > + unsigned long start, unsigned long end, vm_flags_t newflags) > { > - /* Reimplementation to follow in later commit */ > + static const struct mm_walk_ops mlock_walk_ops =3D { > + .pmd_entry =3D mlock_pte_range, > + }; > + > + /* > + * There is a slight chance that concurrent page migration, > + * or page reclaim finding a page of this now-VM_LOCKED vma, > + * will call mlock_vma_page() and raise page's mlock_count: > + * double counting, leaving the page unevictable indefinitely. > + * Communicate this danger to mlock_vma_page() with VM_IO, > + * which is a VM_SPECIAL flag not allowed on VM_LOCKED vmas. > + * mmap_lock is held in write mode here, so this weird > + * combination should not be visible to others. > + */ > + if (newflags & VM_LOCKED) > + newflags |=3D VM_IO; > + WRITE_ONCE(vma->vm_flags, newflags); Nit The WRITE_ONCE is not needed, given the certainty of invisibility to others - it will quiesce syzbot reporting the case of visibility. Hillf > + > + lru_add_drain(); > + walk_page_range(vma->vm_mm, start, end, &mlock_walk_ops, NULL); > + lru_add_drain(); > + > + if (newflags & VM_IO) { > + newflags &=3D ~VM_IO; > + WRITE_ONCE(vma->vm_flags, newflags); > + } > } > =20