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 C5D65C433F5 for ; Wed, 24 Nov 2021 15:26:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0408F6B0075; Wed, 24 Nov 2021 10:26:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F343E6B0078; Wed, 24 Nov 2021 10:26:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF9AB6B007B; Wed, 24 Nov 2021 10:26:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id CDC786B0075 for ; Wed, 24 Nov 2021 10:26:04 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8A7911826CF9C for ; Wed, 24 Nov 2021 15:25:54 +0000 (UTC) X-FDA: 78844199028.18.16B7786 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf18.hostedemail.com (Postfix) with ESMTP id 81601400209B for ; Wed, 24 Nov 2021 15:25:51 +0000 (UTC) Received: by mail-yb1-f169.google.com with SMTP id e136so8352882ybc.4 for ; Wed, 24 Nov 2021 07:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HmxFfSOiSfzWWbUMcFSvrEqVuHmnJJvWCAjgr14F02c=; b=ssPhpk67G6nEvM7D4xW8C7cwz/8zadU0FAkgMsMLTZ1QKGlYOZxvPd5BCp6VLUayF+ hMvfbFgTxXVct98zlIsSCPbNNT8qlihuw7u5qtV2wlQ03s1cSTbjNc0eeYyL6NCeDxAe 3m6rxk4oN6tgjqgGQakjWYaY0jMDk7FZn02y5DwWUoFQGzXSwUf6YtQd3KVu3Lr+fb2x +rhefgexUK9HSsOS+yr+Hfhw9UC5FDJVCtiNYHJPBEsVbAd3a9qWV9T3aFFYUQs1HRHv G4Uuf2eg4H7HcMGShVoV0JggV93Ii7txPN+JTzN4tDJo5hFC3h9thcQ5Acb/Ry9HAjeA 6NAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HmxFfSOiSfzWWbUMcFSvrEqVuHmnJJvWCAjgr14F02c=; b=SIZTR8zXqtA7q6Rysd0aEke4pWeTi+mYvuCeyoAF4imEzUXHFFCVHP1toWrj84Hona eUg08YUfDEMZ5opuiCkgXZ17unO4oGAHZeexdvpGsH5OnENODbsI+kwvNzj2/rG4dIl2 B5cfreoysnKt2pek/eS/QAwbg+IMS55D8kvQBcncnFzHF3WBj3nODpTR5RZlZLXGo5Vw X70yaPIY8hfZS3N74Jrhu3OBNjCfk+C5ZJ7k5mNvZrcKMxLTJQ3iuBRbr+7r9V4XOMoG tS4MBwoDcUCvbjH+DxGzFmEuhcKXL+1KpdtHbAUwWfGv6xq93QvwoniEaXfzj0OD2O8P rHXQ== X-Gm-Message-State: AOAM532z1ZglIlpKlvx9h1gvbhST6rTBWqDO6m7YckiF94jBhgj1nhkP KebEOswBQ8i/Qi06PpjwXdtLY96sTmLf855IHuHlJQ== X-Google-Smtp-Source: ABdhPJyflYv1FyB+vVcXr/eG1/FUusHEXGFu/rw4qq6OeGStWb7PGHzJ6cTWXseh+m5ClqnqSNqMZamlGQ4YVx6kdRM= X-Received: by 2002:a25:d4d5:: with SMTP id m204mr19201030ybf.418.1637767553224; Wed, 24 Nov 2021 07:25:53 -0800 (PST) MIME-Version: 1.0 References: <20211116215715.645231-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 24 Nov 2021 07:25:42 -0800 Message-ID: Subject: Re: [PATCH 1/2] mm: protect free_pgtables with mmap_lock write lock in exit_mmap To: Michal Hocko 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 Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 81601400209B X-Stat-Signature: 9q6axxszmk9hwet68poq4n78p4bjdga3 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ssPhpk67; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of surenb@google.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=surenb@google.com X-HE-Tag: 1637767551-299150 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 Wed, Nov 24, 2021 at 4:20 AM Michal Hocko wrote: > > 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. Thanks for clarification, Michal. I'll post an updated patch with remove_vma() loop executed under mmap_write_lock protection. > -- > Michal Hocko > SUSE Labs