From patchwork Thu Jun 7 22:05:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 10453615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 60AE260375 for ; Thu, 7 Jun 2018 22:05:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 479B02995E for ; Thu, 7 Jun 2018 22:05:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AEE42997A; Thu, 7 Jun 2018 22:05:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A26D02995E for ; Thu, 7 Jun 2018 22:05:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C62BE6B0003; Thu, 7 Jun 2018 18:05:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C38816B0005; Thu, 7 Jun 2018 18:05:49 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B28156B0006; Thu, 7 Jun 2018 18:05:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 731036B0003 for ; Thu, 7 Jun 2018 18:05:49 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id p16-v6so1081808pfn.7 for ; Thu, 07 Jun 2018 15:05:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :subject:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=D+Bz9TnpkdbZzIGiFylv44mQJaUuRBY9n55NN4Z0msA=; b=HeY2ocCFYZICzr+7hROaISNvQD5BwEKq+1pMZa2qwOvebiA5U9pmle4dh9SL/sgc4Q yX80okcXXW9qu/BrY+wWYs6/7xnNk5ms7ruMelwye6mjlK5oXXBkfAxcL+S8i7tIFztU 3wH4YbFzQOiOv/jq7ipiROFBsSFWXloMD4W94hVjvGwAIaHpdoLYkgDg94gpIIFiY8vN 2smiJuNrxKCW8UPUKNJbMaJbbqMYIY85AmN161hZqedm6IulubBthnPiRFV/jqEl0Mxw dbO+NrHJPkL+XqfKO2/wP1pSysMXnKaA87jj9dl27/khp9cGPq0EvKjFG8wwOzMTnacC 31XQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Gm-Message-State: APt69E2QQuNEFDsSFnZDLbrJg5HIyJY1FvJ/jvqm4XzEH4VkomQkc/Ih Okx2xXbs7vJgYn+kl9srAFgwrt1hDOrmNPBaPRq/3ejhKMMLqkGN7UDT0BTMyg9bV2UhXi4+91b Qh2F5ac1lq3fvRj8lC8qGDmbpxtMfIuqBxl/B9TGhxMwboZZAwSLtnra5l9ofgnKqow== X-Received: by 2002:a17:902:ac1:: with SMTP id 59-v6mr3681747plp.36.1528409149135; Thu, 07 Jun 2018 15:05:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLgPNJKyuinoL/YEM+KMJYzr+KS2Zsg7QA5xo7oOKkdJQGb41tN/z2TftbMHmItreYLIEdl X-Received: by 2002:a17:902:ac1:: with SMTP id 59-v6mr3681699plp.36.1528409148330; Thu, 07 Jun 2018 15:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528409148; cv=none; d=google.com; s=arc-20160816; b=UVIIFsoBWexObt7SzaR21iANaH2y312VvZaQPqdIOrNCTt9LiZ81qsD696N/IwPe6F LPQTU/PaO3jyO7YxOt+zvrjiMPHl1gRdAtjqtW1FDpvljNhRLlArKhco6rv5FRUnrFFF bGzy56cf43M4DVPMZCLAI5n2QGJ1XFsfeq2Mp5ePUnkO6oo8TSnSnQZjDbhLbK8+CHwq 1pnqOdTKzNQaUIqdLqdDULyIcjd+FLhpARFGRz0L+477TQmk8Cb3la5lAb2eAq2z/nDM lOydv/q0UuMZ6b0IDAnEAFJYeGPjQ2EYCB3WLmMgw7fYP8+Ma07XRfuXdORopt0bHHC2 7RXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:to:from:date:arc-authentication-results; bh=D+Bz9TnpkdbZzIGiFylv44mQJaUuRBY9n55NN4Z0msA=; b=hwx+TZPSIvCb/26iK50Wt4YQ8hjq64jbrpE+m1GLYuOpn9i09/94nsVG7iTM8tuYGl 6rZMeSN4tcsFJAh+1ixnWtc0UNiN9Qes2NAtkFGG/KV30uUmIqkli+VBhQZXD+v+Yu7b HMCfmGRTN6a3oZn5I0dsdewyk9Nx9q2UEHindiLGFl54n0GYW/1XxbfVHgtjSMBBHK3C Md1pKSap2QiX54y2p7fLf2u9D9KdR+UqdTdvTndO4upF4psocOCcTxu6XTn4u2pa53Re 2jJk/DeLJRI/EydLlLvlM3Np8GUPm9JOC/M3QxOC/F4pcRIWzpG+Tkdsk/OUeqCM1d94 MlMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id k22-v6si20819689pll.416.2018.06.07.15.05.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 15:05:48 -0700 (PDT) Received-SPF: pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) client-ip=140.211.169.12; Authentication-Results: mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 952F589B; Thu, 7 Jun 2018 22:05:47 +0000 (UTC) Date: Thu, 7 Jun 2018 15:05:46 -0700 From: Andrew Morton To: Tetsuo Handa , penguin-kernel@I-love.SAKURA.ne.jp, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, kirill.shutemov@linux.intel.com, mhocko@suse.com, riel@redhat.com, Matthew Wilcox Subject: Re: [PATCH] mm: Check for SIGKILL inside dup_mmap() loop. Message-Id: <20180607150546.1c7db21f70221008e14b8bb8@linux-foundation.org> In-Reply-To: <20180418193254.2db529eeca5d0dc5b82f6b3e@linux-foundation.org> References: <201804071938.CDE04681.SOFVQJFtMHOOLF@I-love.SAKURA.ne.jp> <20180418144401.7c9311079914803c9076d209@linux-foundation.org> <201804190154.w3J1sieH011800@www262.sakura.ne.jp> <20180418193254.2db529eeca5d0dc5b82f6b3e@linux-foundation.org> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP Despite all the discussion, we're short on formal review/ack tags on this one. Here's what I have: From: Tetsuo Handa Subject: mm: check for SIGKILL inside dup_mmap() loop As a theoretical problem, dup_mmap() of an mm_struct with 60000+ vmas can loop while potentially allocating memory, with mm->mmap_sem held for write by current thread. This is bad if current thread was selected as an OOM victim, for current thread will continue allocations using memory reserves while OOM reaper is unable to reclaim memory. As an actually observable problem, it is not difficult to make OOM reaper unable to reclaim memory if the OOM victim is blocked at i_mmap_lock_write() in this loop. Unfortunately, since nobody can explain whether it is safe to use killable wait there, let's check for SIGKILL before trying to allocate memory. Even without an OOM event, there is no point with continuing the loop from the beginning if current thread is killed. I tested with debug printk(). This patch should be safe because we already fail if security_vm_enough_memory_mm() or kmem_cache_alloc(GFP_KERNEL) fails and exit_mmap() handles it. [ 417.030691] ***** Aborting dup_mmap() due to SIGKILL ***** [ 417.036129] ***** Aborting dup_mmap() due to SIGKILL ***** [ 417.044544] ***** Aborting dup_mmap() due to SIGKILL ***** [ 419.116445] ***** Aborting dup_mmap() due to SIGKILL ***** [ 419.118401] ***** Aborting exit_mmap() due to NULL mmap ***** [akpm@linux-foundation.org: add comment] Link: http://lkml.kernel.org/r/201804071938.CDE04681.SOFVQJFtMHOOLF@I-love.SAKURA.ne.jp Signed-off-by: Tetsuo Handa Cc: Alexander Viro Cc: Rik van Riel Cc: Michal Hocko Cc: Kirill A. Shutemov Cc: David Rientjes Signed-off-by: Andrew Morton Reviewed-by: Matthew Wilcox --- kernel/fork.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff -puN kernel/fork.c~mm-check-for-sigkill-inside-dup_mmap-loop kernel/fork.c --- a/kernel/fork.c~mm-check-for-sigkill-inside-dup_mmap-loop +++ a/kernel/fork.c @@ -440,6 +440,14 @@ static __latent_entropy int dup_mmap(str continue; } charge = 0; + /* + * Don't duplicate many vmas if we've been oom-killed (for + * example) + */ + if (fatal_signal_pending(current)) { + retval = -EINTR; + goto out; + } if (mpnt->vm_flags & VM_ACCOUNT) { unsigned long len = vma_pages(mpnt);