Received: by 10.223.185.111 with SMTP id b44csp240861wrg; Fri, 9 Mar 2018 04:19:56 -0800 (PST) X-Google-Smtp-Source: AG47ELt7LZ2SW22dqtaORIJd1jae6DXf5e2KhPfHo3eZHqCkjuUF3LiunE1LFZCeG7Zp4hjAAS4E X-Received: by 2002:a17:902:b683:: with SMTP id c3-v6mr27401897pls.154.1520597996724; Fri, 09 Mar 2018 04:19:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520597996; cv=none; d=google.com; s=arc-20160816; b=t5h//6I34HCxwIqJtnVgXfZdL/+u034129fsJN49hayUZipT7YOBjvboT7DjZ3Vi4S Zi0TWY4lquOyjF43MyhD3Msg6HLzmwaKVBTCm+34q4Ji7LG29QUAOb1LwSlxOylJMj2g CJronclwfE68gYqSmyGOndjZeq1ALuZDtQ0VKKr614d9V3V31e9nAyAbuTHYJo9u8a/S H8BBYD4Bj07BW2Iu1z2cm1uz94aoQz9fmbaHTmTn0fYsmFGu4hv/uexTboxf40l9SjCy z9Yf05tc1ck18diY8tOAaJ4UigayyPA6TnrAoFBAf4Md7edwnZ8cU0NJLYQ8QWa9Uz+f M+CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:date:message-id:in-reply-to :references:from:subject:cc:to:arc-authentication-results; bh=4cpoT9AAm6HLY7+7Ra6flkr/0v2RHvmDLxcMRL92G+g=; b=Cq8KsuRM8pQnX6PcdmLaaO5ReKuZI9ecRIG7dG+O5M8I5yz4zZdMvinrfKCTgHHxxP 29G/nAAeNNy8iTfM/MW8I1305+lg2/Xs/NZIfoDV1efXk03S3OmY4a9YZ7FeuKTBflli 4ZmXXMP+WOnrSRc6+oRDcwtF34/fteT9PLorjlSuUGyELDk6yoXOhkhRut6C3BCBnzSv P6hgnz7BkbQKBrIYbeEr+nSmcYPqR5gT5B1Ikh/adgupB6HSfmvGZiAyioAKbphgg270 NAraonL1fAt4gltX7vaI5w2jM60eHeTTT3pEPbAqCqxxk3Jkb4x/g8d/5xccw7iXPIwQ u1iA== 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 u3si637833pgr.447.2018.03.09.04.19.41; Fri, 09 Mar 2018 04:19:56 -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 S1751092AbeCIMSr (ORCPT + 99 others); Fri, 9 Mar 2018 07:18:47 -0500 Received: from www262.sakura.ne.jp ([202.181.97.72]:50195 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750966AbeCIMSq (ORCPT ); Fri, 9 Mar 2018 07:18:46 -0500 Received: from fsav104.sakura.ne.jp (fsav104.sakura.ne.jp [27.133.134.231]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w29CITfB029595; Fri, 9 Mar 2018 21:18:29 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav104.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav104.sakura.ne.jp); Fri, 09 Mar 2018 21:18:29 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav104.sakura.ne.jp) Received: from AQUA (softbank126099184120.bbtec.net [126.99.184.120]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w29CIT27029592; Fri, 9 Mar 2018 21:18:29 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) To: gkohli@codeaurora.org, rientjes@google.com Cc: akpm@linux-foundation.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, aarcange@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH] mm: oom: Fix race condition between oom_badness and do_exit of task From: Tetsuo Handa References: <22ebd655-ece4-37e5-5a98-e9750cb20665@codeaurora.org> <14ba6c44-d444-bd0a-0bac-0c6851b19344@codeaurora.org> <201803091948.FBC21396.LHOMSFFOVFtQJO@I-love.SAKURA.ne.jp> In-Reply-To: Message-Id: <201803092118.CCH34154.HOVLQFOFMJtFOS@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Fri, 9 Mar 2018 21:18:28 +0900 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kohli, Gaurav wrote: > On 3/9/2018 4:18 PM, Tetsuo Handa wrote: > > > Kohli, Gaurav wrote: > >>> t->alloc_lock is still held when leaving find_lock_task_mm(), which means > >>> that t->mm != NULL. But nothing prevents t from setting t->mm = NULL at > >>> exit_mm() from do_exit() and calling exit_creds() from __put_task_struct(t) > >>> after task_unlock(t) is called. Seems difficult to trigger race window. Maybe > >>> something has preempted because oom_badness() becomes outside of RCU grace > >>> period upon leaving find_lock_task_mm() when called from proc_oom_score(). > >> Hi Tetsuo, > >> > >> Yes it is not easy to reproduce seen twice till now and i agree with > >> your analysis. But David has already fixing this in different way, > >> So that also looks better to me: > >> > >> https://patchwork.kernel.org/patch/10265641/ > >> > > Yes, I'm aware of that patch. > > > >> But if need to keep that code, So we have to bump up the task > >> reference that's only i can think of now. > > I don't think so, for I think it is safe to call > > has_capability_noaudit(p) with p->alloc_lock held. > > > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > > index f2e7dfb..4efcfb8 100644 > > --- a/mm/oom_kill.c > > +++ b/mm/oom_kill.c > > @@ -222,7 +222,6 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg, > > */ > > points = get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) + > > mm_pgtables_bytes(p->mm) / PAGE_SIZE; > > - task_unlock(p); > > > > /* > > * Root processes get 3% bonus, just like the __vm_enough_memory() > > @@ -230,6 +229,7 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg, > > */ > > if (has_capability_noaudit(p, CAP_SYS_ADMIN)) > > points -= (points * 3) / 100; > > + task_unlock(p); > > Earlier i have thought the same to post this, but this may create > problem if there are sleeping calls in > > has_capability_noaudit ? has_capability_noaudit() does not sleep. See what has_ns_capability_noaudit() is doing. > > > > > /* Normalize to oom_score_adj units */ > > adj *= totalpages / 1000; > > > -- > Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project. > >