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 52135C433EF for ; Fri, 10 Dec 2021 09:20:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDC976B0071; Fri, 10 Dec 2021 04:20:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8CC66B0072; Fri, 10 Dec 2021 04:20:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A83086B0074; Fri, 10 Dec 2021 04:20:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id 99AD26B0071 for ; Fri, 10 Dec 2021 04:20:20 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5850D7F90D for ; Fri, 10 Dec 2021 09:20:10 +0000 (UTC) X-FDA: 78901338180.31.49BB7F6 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf03.hostedemail.com (Postfix) with ESMTP id DE71620005 for ; Fri, 10 Dec 2021 09:20:09 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9D8811F3A1; Fri, 10 Dec 2021 09:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1639128008; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gDjp6nHahr/gQejvxC0DydQpWXBPwmoZeSh1rjN3KPY=; b=Xa3gad8UdHYNjT6v8zs4Y+hmpmuy5AAQRylzfTUZ97yLKl3e8/6Uc3H0b/Pj9aySJZr9Zl QJYAt76fByzuNLu0GJ/OnqSqip4UxCWLM+hVqnAN7VIleVPWiXzuMtXhG543XgtlZ1X2N0 9vuKHxfPvnC7D7sao8ATRYxK8vQSz6Y= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 7EA75A3B9A; Fri, 10 Dec 2021 09:20:07 +0000 (UTC) Date: Fri, 10 Dec 2021 10:20:06 +0100 From: Michal Hocko To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, rientjes@google.com, willy@infradead.org, hannes@cmpxchg.org, guro@fb.com, riel@surriel.com, minchan@kernel.org, kirill@shutemov.name, aarcange@redhat.com, christian@brauner.io, hch@infradead.org, oleg@redhat.com, david@redhat.com, jannh@google.com, shakeelb@google.com, luto@kernel.org, christian.brauner@ubuntu.com, fweimer@redhat.com, jengelh@inai.de, timmurray@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v4 1/3] mm: protect free_pgtables with mmap_lock write lock in exit_mmap Message-ID: References: <20211208212211.2860249-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: gtpy1514hkwb88unqzn6xbxzdnthbztz Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Xa3gad8U; spf=pass (imf03.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: DE71620005 X-HE-Tag: 1639128009-794740 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 Thu 09-12-21 11:03:11, Suren Baghdasaryan wrote: > On Thu, Dec 9, 2021 at 12:55 AM Michal Hocko wrote: > > > > On Wed 08-12-21 13:22:09, Suren Baghdasaryan wrote: > > > oom-reaper and process_mrelease system call should protect against > > > races with exit_mmap which can destroy page tables while they > > > walk the VMA tree. oom-reaper protects from that race by setting > > > MMF_OOM_VICTIM and by relying on exit_mmap to set MMF_OOM_SKIP > > > before taking and releasing mmap_write_lock. process_mrelease has > > > to elevate mm->mm_users to prevent such race. Both oom-reaper and > > > process_mrelease hold mmap_read_lock when walking the VMA tree. > > > The locking rules and mechanisms could be simpler if exit_mmap takes > > > mmap_write_lock while executing destructive operations such as > > > free_pgtables. > > > Change exit_mmap to hold the mmap_write_lock when calling > > > free_pgtables and remove_vma. Operations like unmap_vmas and > > > unlock_range are not destructive and could run under mmap_read_lock > > > but for simplicity we take one mmap_write_lock during almost the entire > > > operation. > > > > unlock_range is not safe to be called under read lock. See 27ae357fa82b > > ("mm, oom: fix concurrent munlock and oom reaper unmap, v3"). > > Ok, I'll remove the sentence above. > Is my understanding correct that it is unsafe only because oom-reaper > can't deal with VM_LOCKED, otherwise it would be fine? The commit message (27ae357fa82b) goes into details that I have forgot already. -- Michal Hocko SUSE Labs