From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751881AbdKYBxK (ORCPT ); Fri, 24 Nov 2017 20:53:10 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11423 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751681AbdKYBxJ (ORCPT ); Fri, 24 Nov 2017 20:53:09 -0500 Subject: Re: [PATCH] mm,madvise: bugfix of madvise systemcall infinite loop under special circumstances. To: Michal Hocko References: <20171124022757.4991-1-guoxuenan@huawei.com> <20171124080507.u76g634hucoxmpov@dhcp22.suse.cz> <829af987-4d65-382c-dbd4-0c81222ebb51@huawei.com> <20171124130803.hafb3zbhy7gdqkvi@dhcp22.suse.cz> CC: , , , , , , , , , , , , , , From: =?UTF-8?B?6YOt6Zuq5qWg?= Message-ID: <52b8bab4-6656-fe76-ed21-ee3c4682a5e3@huawei.com> Date: Sat, 25 Nov 2017 09:52:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20171124130803.hafb3zbhy7gdqkvi@dhcp22.suse.cz> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.219.194] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.5A18CCFC.006D,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: e02d13f20dd278dea3774c5f18aa85bd Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yes , your modification is much better! thanks. 在 2017/11/24 21:08, Michal Hocko 写道: > On Fri 24-11-17 20:51:29, 郭雪楠 wrote: >> Sorry,I explained wrong before. But,I've tested using trinity in DAX >> mode,and I'am sure it has possibility of triggering an soft lockup. I have >> encountered the problem of endless loop here . >> >> I had a little problem here,I correct it . >> under Initial state : >> [ start = vam->vm_start < vam->vm_end < end ] >> >> When [start = vam->vm_start] the program enters for{;;} loop >> ,find_vma_prev() will set the pointer vma and the pointer prev (prev = >> vam->vm_prev ). Normally ,madvise_vma() will always move the pointer prev >> ,but when use DAX mode , it will never update . > [...] >> if (prev) // here prev not NULL,it will always enter this branch .. >> vma = prev->vm_next; >> else /* madvise_remove dropped mmap_sem */ >> vma = find_vma(current->mm, start); > > You are right! My fault, I managed to confuse myself in the code flow. > It really looks like this has been broken for more than 10 years since > fe77ba6f4f97 ("[PATCH] xip: madvice/fadvice: execute in place"). > > Maybe the following would be more readable and less error prone? > --- > diff --git a/mm/madvise.c b/mm/madvise.c > index 375cf32087e4..a631c414f915 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -276,30 +276,26 @@ static long madvise_willneed(struct vm_area_struct *vma, > { > struct file *file = vma->vm_file; > > + *prev = vma; > #ifdef CONFIG_SWAP > if (!file) { > - *prev = vma; > force_swapin_readahead(vma, start, end); > return 0; > } > > - if (shmem_mapping(file->f_mapping)) { > - *prev = vma; > + if (shmem_mapping(file->f_mapping)) > force_shm_swapin_readahead(vma, start, end, > file->f_mapping); > return 0; > - } > #else > if (!file) > return -EBADF; > #endif > > - if (IS_DAX(file_inode(file))) { > + if (IS_DAX(file_inode(file))) > /* no bad return value, but ignore advice */ > return 0; > - } > > - *prev = vma; > start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; > if (end > vma->vm_end) > end = vma->vm_end; >