Received: by 10.223.176.5 with SMTP id f5csp1993895wra; Sun, 4 Feb 2018 17:41:43 -0800 (PST) X-Google-Smtp-Source: AH8x224+22xmDlDQO1qCv0hBotg+q1TxZEbUdilNj/5uH4QL6cvrzJMJ4pU6S0k79Bw99JH1cMlJ X-Received: by 10.98.112.4 with SMTP id l4mr46830246pfc.8.1517794903698; Sun, 04 Feb 2018 17:41:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517794903; cv=none; d=google.com; s=arc-20160816; b=mu+Wl0nBzGRwfjwuQNSwDv306+Of/TqWqjOn+wDUBAbOfcRSbB7QBkaB9wviAhy1qb 9EzGmEZ9eqFVGEPQerbIb1qFWFIcOJqO4/cP3QBduQOgaFK5vznacEBSKl2kxKrWQPBi 3gqlTK5gSMnWadzrtozT0kK3AA0x6sy2DwCiVZdQQ1bdLAPl9WJcbnrlNNqELX/68S6a eOcM4kQYl6ozaSrrdDNR+xqIldzIY5upyKQ5+2kc6kvY60ixg3rVDXzlh1gK1r4en06x CAxG6p0+KYWXCSgt+H69WwImXIcXMLaYGNprPc1t/li61omHRkzzkmlRZbnphmJQhHiO opOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Ubo7Lg98WtQU4yXrXuY2Ji0y2s3QpRNkCNNf1LpTuoo=; b=fHMHmiZ+GLDCbK9cPVPJEjUDTMTo4IpsMttaMPUnDEM4jNdKUxmCcKSMLmIz5B706h XK6N8bAjq2JL83ufJBuuA9YTPtqkM52iA9ncHDDTxjGaks+F6V2q8IGx2O6n76oH0OgW LLHnnHuMCuNURKBn1GRwikT4ILwyLM3KL2Y+Q1sztU/T1VJ0iik1kwpK4G/DNr818c9v vgdCmEc+V6OgZJXp8BED15NAk9OABW8UU30VwnJbQzjPsUMUUf4ZuDgYaLy3tXiMHMH2 V/0qud3GSlatedJb+EbuorT3/B5kkgWiuhAURM5OtU018YyW/IXuh94w7d4LwwAtNM9T DWIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q12-v6si4086539plr.434.2018.02.04.17.41.29; Sun, 04 Feb 2018 17:41:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752249AbeBEBjU (ORCPT + 99 others); Sun, 4 Feb 2018 20:39:20 -0500 Received: from mx2.suse.de ([195.135.220.15]:44135 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752686AbeBEB23 (ORCPT ); Sun, 4 Feb 2018 20:28:29 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 87E28ADF8; Mon, 5 Feb 2018 01:28:00 +0000 (UTC) From: Davidlohr Bueso To: akpm@linux-foundation.org, mingo@kernel.org Cc: peterz@infradead.org, ldufour@linux.vnet.ibm.com, jack@suse.cz, mhocko@kernel.org, kirill.shutemov@linux.intel.com, mawilcox@microsoft.com, mgorman@techsingularity.net, dave@stgolabs.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 14/64] fs/coredump: teach about range locking Date: Mon, 5 Feb 2018 02:27:04 +0100 Message-Id: <20180205012754.23615-15-dbueso@wotan.suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180205012754.23615-1-dbueso@wotan.suse.de> References: <20180205012754.23615-1-dbueso@wotan.suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Davidlohr Bueso coredump_wait() needs mmap_sem such that zap_threads() is stable. The conversion is trivial as the mmap_sem is only used in the same function context. No change in semantics. In addition, we need an mmrange in exec_mmap() as mmap_sem is needed for de_thread() or coredump (for core_state and changing tsk->mm) scenarios. No change in semantics. Signed-off-by: Davidlohr Bueso --- fs/coredump.c | 5 +++-- fs/exec.c | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index 1e2c87acac9b..ad91712498fc 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -412,17 +412,18 @@ static int coredump_wait(int exit_code, struct core_state *core_state) struct task_struct *tsk = current; struct mm_struct *mm = tsk->mm; int core_waiters = -EBUSY; + DEFINE_RANGE_LOCK_FULL(mmrange); init_completion(&core_state->startup); core_state->dumper.task = tsk; core_state->dumper.next = NULL; - if (down_write_killable(&mm->mmap_sem)) + if (mm_write_lock_killable(mm, &mmrange)) return -EINTR; if (!mm->core_state) core_waiters = zap_threads(tsk, mm, core_state, exit_code); - up_write(&mm->mmap_sem); + mm_write_unlock(mm, &mmrange); if (core_waiters > 0) { struct core_thread *ptr; diff --git a/fs/exec.c b/fs/exec.c index e46752874b47..a61ac9e81169 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -294,12 +294,13 @@ static int __bprm_mm_init(struct linux_binprm *bprm) int err; struct vm_area_struct *vma = NULL; struct mm_struct *mm = bprm->mm; + DEFINE_RANGE_LOCK_FULL(mmrange); bprm->vma = vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL); if (!vma) return -ENOMEM; - if (down_write_killable(&mm->mmap_sem)) { + if (mm_write_lock_killable(mm, &mmrange)) { err = -EINTR; goto err_free; } @@ -324,11 +325,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm) mm->stack_vm = mm->total_vm = 1; arch_bprm_mm_init(mm, vma); - up_write(&mm->mmap_sem); + mm_write_unlock(mm, &mmrange); bprm->p = vma->vm_end - sizeof(void *); return 0; err: - up_write(&mm->mmap_sem); + mm_write_unlock(mm, &mmrange); err_free: bprm->vma = NULL; kmem_cache_free(vm_area_cachep, vma); @@ -739,7 +740,7 @@ int setup_arg_pages(struct linux_binprm *bprm, bprm->loader -= stack_shift; bprm->exec -= stack_shift; - if (down_write_killable(&mm->mmap_sem)) + if (mm_write_lock_killable(mm, &mmrange)) return -EINTR; vm_flags = VM_STACK_FLAGS; @@ -796,7 +797,7 @@ int setup_arg_pages(struct linux_binprm *bprm, ret = -EFAULT; out_unlock: - up_write(&mm->mmap_sem); + mm_write_unlock(mm, &mmrange); return ret; } EXPORT_SYMBOL(setup_arg_pages); @@ -1011,6 +1012,7 @@ static int exec_mmap(struct mm_struct *mm) { struct task_struct *tsk; struct mm_struct *old_mm, *active_mm; + DEFINE_RANGE_LOCK_FULL(mmrange); /* Notify parent that we're no longer interested in the old VM */ tsk = current; @@ -1025,9 +1027,9 @@ static int exec_mmap(struct mm_struct *mm) * through with the exec. We must hold mmap_sem around * checking core_state and changing tsk->mm. */ - down_read(&old_mm->mmap_sem); + mm_read_lock(old_mm, &mmrange); if (unlikely(old_mm->core_state)) { - up_read(&old_mm->mmap_sem); + mm_read_unlock(old_mm, &mmrange); return -EINTR; } } @@ -1040,7 +1042,7 @@ static int exec_mmap(struct mm_struct *mm) vmacache_flush(tsk); task_unlock(tsk); if (old_mm) { - up_read(&old_mm->mmap_sem); + mm_read_unlock(old_mm, &mmrange); BUG_ON(active_mm != old_mm); setmax_mm_hiwater_rss(&tsk->signal->maxrss, old_mm); mm_update_next_owner(old_mm); -- 2.13.6