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 A9BC8C433EF for ; Wed, 24 Nov 2021 12:21:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FF076B0075; Wed, 24 Nov 2021 07:20:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AF436B0078; Wed, 24 Nov 2021 07:20:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09E296B007B; Wed, 24 Nov 2021 07:20:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id EEA3F6B0075 for ; Wed, 24 Nov 2021 07:20:51 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B23038995E for ; Wed, 24 Nov 2021 12:20:41 +0000 (UTC) X-FDA: 78843732324.14.CE4185A Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf04.hostedemail.com (Postfix) with ESMTP id D35D250000BD for ; Wed, 24 Nov 2021 12:20:37 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id CF31021941; Wed, 24 Nov 2021 12:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1637756439; 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=x051lL+rIcViyFMqRM8uVRQZz+CCvBR7eit+ORyQOVA=; b=qV8/E86W9MN7uvn5lwYq6hoKppSZf24lyYq0Wpea70I7YQZFNgLTuAhnkxsyOcmcLc04bX //grjHPmsfSdKJbmMDXmDTQE8QwyI+2hAP/b/N5yD+3BM9RWYnhc8c219LlD8Sh7BvEKby n0eknJVgel1u3X+dEUvo+CsEA4ygxN0= 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 51409A3B84; Wed, 24 Nov 2021 12:20:39 +0000 (UTC) Date: Wed, 24 Nov 2021 13:20:35 +0100 From: Michal Hocko To: Suren Baghdasaryan Cc: Matthew Wilcox , akpm@linux-foundation.org, rientjes@google.com, 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 1/2] mm: protect free_pgtables with mmap_lock write lock in exit_mmap Message-ID: References: <20211116215715.645231-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: D35D250000BD X-Stat-Signature: aws9gh4hz51tn8w5t8j19gomdspd7jcf Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b="qV8/E86W"; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf04.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspamd-Server: rspam02 X-HE-Tag: 1637756437-581020 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 Tue 23-11-21 09:56:41, Suren Baghdasaryan wrote: > On Tue, Nov 23, 2021 at 5:19 AM Matthew Wilcox wrote: > > > > On Tue, Nov 16, 2021 at 01:57:14PM -0800, Suren Baghdasaryan wrote: > > > @@ -3170,6 +3172,7 @@ void exit_mmap(struct mm_struct *mm) > > > unmap_vmas(&tlb, vma, 0, -1); > > > free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); > > > tlb_finish_mmu(&tlb); > > > + mmap_write_unlock(mm); > > > > > > /* > > > * Walk the list again, actually closing and freeing it, > > > > Is there a reason to unlock here instead of after the remove_vma loop? > > We'll need the mmap sem held during that loop when VMAs are stored in > > the maple tree. > > I didn't realize remove_vma() would need to be protected as well. I > think I can move mmap_write_unlock down to cover the last walk too > with no impact. > Does anyone know if there was any specific reason to perform that last > walk with no locks held (as the comment states)? I can track that > comment back to Linux-2.6.12-rc2 merge with no earlier history, so not > sure if it's critical not to hold any locks at this point. Seems to me > it's ok to hold mmap_write_unlock but maybe I'm missing something? I suspect the primary reason was that neither fput (and callbacks invoked from it) nor vm_close would need to be very careful about interacting with mm locks. fput is async these days so it shouldn't be problematic. vm_ops->close doesn't have any real contract definition AFAIK but taking mmap_sem from those would be really suprising. They should be mostly destructing internal vma state and that shouldn't really require address space protection. -- Michal Hocko SUSE Labs