Received: by 10.223.164.202 with SMTP id h10csp441464wrb; Mon, 6 Nov 2017 09:09:56 -0800 (PST) X-Google-Smtp-Source: ABhQp+QKAUS7a79XLlfL3oRJmAWzbgvU49ZEs5Vf9R6MPtfzm8HVeFgSpK0YSceVA2LR8mCsq3dK X-Received: by 10.98.69.86 with SMTP id s83mr17642973pfa.32.1509988196545; Mon, 06 Nov 2017 09:09:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509988196; cv=none; d=google.com; s=arc-20160816; b=J6qEk9SynKsgq08VoVErxBWMVUXG9/iNDlUjc7VBbbVoSiCS/bv16VQYNMF0kbB1+B jquA4pdnebvSkWyCQYVTJ5foXWUkiO7IHoGEimi/Pid3RbqIiWTq6wAAttre7tbAiRT/ BECsrdXZUN1KdAVKpuFLj7Ke88u6UTLW2QxmhCrW816ulQeQfeYLkFqYFuS8EQEhRkLN Go3W81DvygI6qfJTDn0lG5JhEkrwnAlZZruVgmwrbfjGtmGQ9FDinmMCDLj7Y7yBJNCQ RC//fjQeUS6inyLc/Ir/V009qsiAupZfRSMkHetrPmb1HsbCvJpdtRRttk8TAIHHB3o1 BVMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=rAw+Qt5oLLWRutWtjDQzemslejqtzdSY1/0aKPZzULk=; b=ZDBLw67iZIbI9hGfFnknktRMZ23UGyY7wJVr1tQSq4b7FO1NlsAOkAZfWLkSYo2Kws Cl4rdEiMTDJ0hYm5ct7Jl3pUOCGV2gFnGMe/gb+dueryCLU0DAxND3Rg2MOZVYaVm0Cf TV4ChJLcWgNkEotdde8s4F0CAEesZOFvhx+eBLyP/M2vOVHtyhjDW6+WJQUimHXWcQo9 yHC47k1Htotv3gwdnyyfM7phRLW19uMqo0ineirWqZADzkxn1aZ+C7JccwF3W5dO2N87 WxPKQt4bvu9jXOD4IqyaRTCdIPluXzmbHmjZzvFGsvuqxhemEwCdAv4tRyo+bAJmpQMM luog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alibaba-inc.com header.s=default header.b=jAbrRFHk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba-inc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si12072690pfh.239.2017.11.06.09.09.42; Mon, 06 Nov 2017 09:09: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; dkim=pass header.i=@alibaba-inc.com header.s=default header.b=jAbrRFHk; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba-inc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754179AbdKFQRc (ORCPT + 97 others); Mon, 6 Nov 2017 11:17:32 -0500 Received: from out0-250.mail.aliyun.com ([140.205.0.250]:41818 "EHLO out0-250.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753207AbdKFQRX (ORCPT ); Mon, 6 Nov 2017 11:17:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alibaba-inc.com; s=default; t=1509985032; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type; bh=rAw+Qt5oLLWRutWtjDQzemslejqtzdSY1/0aKPZzULk=; b=jAbrRFHkxS37B7KDEHRlky2+9Lgg7MB0VIVYVR8VlQBEdO+GmC54QVkvj4Nh9GjIM6oa/tug7le64GiUXgQKTAH5kIUHdZWEsym9Rvr1d7m36PnKfPd9ZgoO40U6UsvDYwC49IkHj4uBCaBxGt1azdiNVqnBrN3ZUB2T35hlUWE= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R871e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03280;MF=yang.s@alibaba-inc.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---.9L8Km2k_1509985024; Received: from US-143344MP.local(mailfrom:yang.s@alibaba-inc.com ip:121.0.29.200) by smtp.aliyun-inc.com(127.0.0.1); Tue, 07 Nov 2017 00:17:06 +0800 Subject: Re: [PATCH] mm: do not rely on preempt_count in print_vma_addr To: Michal Hocko , Peter Zijlstra Cc: Bart Van Assche , "akpm@linux-foundation.org" , "joe@perches.com" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "mingo@redhat.com" References: <1509572313-102989-1-git-send-email-yang.s@alibaba-inc.com> <20171102075744.whhxjmqbdkfaxghd@dhcp22.suse.cz> <20171103110245.7049460a05cc18c7e8a9feb2@linux-foundation.org> <1509739786.2473.33.camel@wdc.com> <20171105081946.yr2pvalbegxygcky@dhcp22.suse.cz> <20171106100558.GD3165@worktop.lehotels.local> <20171106104354.2jlgd2m4j4gxx4qo@dhcp22.suse.cz> <20171106120025.GH3165@worktop.lehotels.local> <20171106121222.nnzrr4cb7s7y5h74@dhcp22.suse.cz> <20171106134031.g6dbelg55mrbyc6i@dhcp22.suse.cz> From: "Yang Shi" Message-ID: <8665ccad-fa48-b835-c2e0-e50a4f05f319@alibaba-inc.com> Date: Tue, 07 Nov 2017 00:16:58 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20171106134031.g6dbelg55mrbyc6i@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/6/17 5:40 AM, Michal Hocko wrote: > On Mon 06-11-17 13:12:22, Michal Hocko wrote: >> On Mon 06-11-17 13:00:25, Peter Zijlstra wrote: >>> On Mon, Nov 06, 2017 at 11:43:54AM +0100, Michal Hocko wrote: >>>>> Yes the comment is very much accurate. >>>> >>>> Which suggests that print_vma_addr might be problematic, right? >>>> Shouldn't we do trylock on mmap_sem instead? >>> >>> Yes that's complete rubbish. trylock will get spurious failures to print >>> when the lock is contended. >> >> Yes, but I guess that it is acceptable to to not print the state under >> that condition. > > So what do you think about this? I think this is more robust than > playing tricks with the explicit preempt count checks and less tedious > than checking to make it conditional on the context. This is on top of > Linus tree and if accepted it should replace the patch discussed here. > --- > From 0de6d57cbc54ee2686d1f1e4ffcc4ed490ded8aa Mon Sep 17 00:00:00 2001 > From: Michal Hocko > Date: Mon, 6 Nov 2017 14:31:20 +0100 > Subject: [PATCH] mm: do not rely on preempt_count in print_vma_addr > > The preempt count check on print_vma_addr has been added by e8bff74afbdb > ("x86: fix "BUG: sleeping function called from invalid context" in > print_vma_addr()") and it relied on the elevated preempt count from > preempt_conditional_sti because preempt_count check doesn't work on > non preemptive kernels by default. The code has evolved though and > d99e1bd175f4 ("x86/entry/traps: Refactor preemption and interrupt flag > handling") has replaced preempt_conditional_sti by an explicit > preempt_disable which is noop on !PREEMPT so the check in print_vma_addr > is broken. > > Fix the issue by using trylock on mmap_sem rather than chacking the s/chacking/checking > preempt count. The allocation we are relying on has to be GFP_NOWAIT > as well. There is a chance that we won't dump the vma state if the lock > is contended or the memory short but this is acceptable outcome and much > less fragile than the not working preemption check or tricks around it. > > Fixes: d99e1bd175f4 ("x86/entry/traps: Refactor preemption and interrupt flag handling") > Signed-off-by: Michal Hocko Acked-by: Yang Shi Regards, Yang > --- > mm/memory.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index a728bed16c20..1e308ac8ca0a 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4457,17 +4457,15 @@ void print_vma_addr(char *prefix, unsigned long ip) > struct vm_area_struct *vma; > > /* > - * Do not print if we are in atomic > - * contexts (in exception stacks, etc.): > + * we might be running from an atomic context so we cannot sleep > */ > - if (preempt_count()) > + if (!down_read_trylock(&mm->mmap_sem)) > return; > > - down_read(&mm->mmap_sem); > vma = find_vma(mm, ip); > if (vma && vma->vm_file) { > struct file *f = vma->vm_file; > - char *buf = (char *)__get_free_page(GFP_KERNEL); > + char *buf = (char *)__get_free_page(GFP_NOWAIT); > if (buf) { > char *p; > > From 1583334901008470573@xxx Mon Nov 06 16:30:29 +0000 2017 X-GM-THRID: 1583326809651580499 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread