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 301DBC433F5 for ; Thu, 9 Dec 2021 08:59:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 994D36B0071; Thu, 9 Dec 2021 03:59:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91DC26B0073; Thu, 9 Dec 2021 03:59:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BE826B0074; Thu, 9 Dec 2021 03:59:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id 6847E6B0071 for ; Thu, 9 Dec 2021 03:59:16 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1DEF7181AC9CC for ; Thu, 9 Dec 2021 08:59:06 +0000 (UTC) X-FDA: 78897656292.31.EC73CA3 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf07.hostedemail.com (Postfix) with ESMTP id 8E9CB40008 for ; Thu, 9 Dec 2021 08:59:05 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 82B97210FF; Thu, 9 Dec 2021 08:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1639040344; 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=YWsMjWejwfhqv/d2S29G1vAIT34xji/2SKWuQfXw5K8=; b=Oj5leA1irmEIVS38sLDs8L6lMXhTC3eucjbNFykrBPhzvl71r1t8FByE3XRHDoyxD71Q7o WLL39CJ8G/i0k8QO0golzFyLUs0DulUJjQeM7Uq3a+MI6QnNk5Ps3l190H212iz5RjnD/C czZEDHihlQLA2oN1MrJSv9gyDAJyKKU= 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 1B254A3B95; Thu, 9 Dec 2021 08:59:04 +0000 (UTC) Date: Thu, 9 Dec 2021 09:59:03 +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 3/3] mm/oom_kill: allow process_mrelease to run under mmap_lock protection Message-ID: References: <20211208212211.2860249-1-surenb@google.com> <20211208212211.2860249-3-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211208212211.2860249-3-surenb@google.com> Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=Oj5leA1i; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf07.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 8E9CB40008 X-Stat-Signature: oaamgzcr9pgoaonwue49d8huy9qbdgir X-HE-Tag: 1639040345-680773 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 08-12-21 13:22:11, Suren Baghdasaryan wrote: > With exit_mmap holding mmap_write_lock during free_pgtables call, > process_mrelease does not need to elevate mm->mm_users in order to > prevent exit_mmap from destrying pagetables while __oom_reap_task_mm > is walking the VMA tree. The change prevents process_mrelease from > calling the last mmput, which can lead to waiting for IO completion > in exit_aio. > > Fixes: 337546e83fc7 ("mm/oom_kill.c: prevent a race between process_mrelease and exit_mmap") I am not sure I have brought this up already but I do not think Fixes tag is a good fit. 337546e83fc7 is a correct way to handle the race. It is just slightly less optimal than this fix. > Signed-off-by: Suren Baghdasaryan Acked-by: Michal Hocko Thanks! > --- > mm/oom_kill.c | 27 +++++++++++++++------------ > 1 file changed, 15 insertions(+), 12 deletions(-) > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 1ddabefcfb5a..67780386f478 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -1169,15 +1169,15 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags) > goto put_task; > } > > - if (mmget_not_zero(p->mm)) { > - mm = p->mm; > - if (task_will_free_mem(p)) > - reap = true; > - else { > - /* Error only if the work has not been done already */ > - if (!test_bit(MMF_OOM_SKIP, &mm->flags)) > - ret = -EINVAL; > - } > + mm = p->mm; > + mmgrab(mm); > + > + if (task_will_free_mem(p)) > + reap = true; > + else { > + /* Error only if the work has not been done already */ > + if (!test_bit(MMF_OOM_SKIP, &mm->flags)) > + ret = -EINVAL; > } > task_unlock(p); > > @@ -1188,13 +1188,16 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags) > ret = -EINTR; > goto drop_mm; > } > - if (!__oom_reap_task_mm(mm)) > + /* > + * Check MMF_OOM_SKIP again under mmap_read_lock protection to ensure > + * possible change in exit_mmap is seen > + */ > + if (!test_bit(MMF_OOM_SKIP, &mm->flags) && !__oom_reap_task_mm(mm)) > ret = -EAGAIN; > mmap_read_unlock(mm); > > drop_mm: > - if (mm) > - mmput(mm); > + mmdrop(mm); > put_task: > put_task_struct(task); > return ret; > -- > 2.34.1.400.ga245620fadb-goog -- Michal Hocko SUSE Labs