Received: by 10.223.164.202 with SMTP id h10csp1576616wrb; Mon, 27 Nov 2017 04:45:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMb00MM+nmLQzQel8b+22xO5+cSxs+yTv8Y3sehk00gH9t8Tt2Xh1/VJQcsD3pQ4DIXJ6H9e X-Received: by 10.101.74.8 with SMTP id s8mr36169095pgq.259.1511786744914; Mon, 27 Nov 2017 04:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511786744; cv=none; d=google.com; s=arc-20160816; b=R7ShID2jzw/YqfV6OBL5x9dv2Bc76dAHss0uCyLmSMMroxTYjwEDQ+nE9cfbzl4ysk JSzfKvMwyQWi+ZB/AF35t+jmJ6HMO0haHnm99xyY5nQOTBEzlRuEMM94z8G5PlwR/0Ao FQeMqn5GaUjYFAA1waUaZ9nXZM17Z/JGnvZ6JiL02SAeTz3l3ukV53sB4nYDGdBNmLHK RWcZhOjthHNJkAnlkSODvNM5X7hCo+89Pb5Taa9W3bCSJr5KCZb7UMY24ACQgWN+3C7e 3lKPNxLKtYZAF/X+l9i4KbnqLiWSx+It8TTCL70yO4rzGJ9Ej8b+8uB7v4c8xx5enYOK zhAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:subject:cc:to:from:date:arc-authentication-results; bh=/WcMt4iSxmyyeDKMilGQc6/8BpMkZ9RyAWXsdP6NihM=; b=vVYvdvlai5XluaXq3UZEWw74yTpJuWgKJhtEEC3sNGx7AHoUyFjmlmzQLvQq6E7yOf bAUTxtWSanFTXzKs+tfMBHPjv6K0Kff+iEgjq92OmS1hB7Y0sxYAc6STq/vHc6TBGkAc GLokRadrzFURG69u0Ayl46+8l6Qs3SWjzaMzF36PqnNoaUg9CgVvagf2BLQ/HkBgFTuk x4rm71qkPYrUeLFZD4YIZDII+9WC+bUbP5WWXof75sfTIdXKa9ka878Ax3DPuhpnMXWh Rw6rX3/zeL4B/oeNLfJSOlucOMyKyr2DQIufxih6oxni5SszSnCe6/pNHcMGPNoz3uyE 9R7A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v22si25418045pfa.282.2017.11.27.04.45.25; Mon, 27 Nov 2017 04:45:44 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752128AbdK0MnA (ORCPT + 77 others); Mon, 27 Nov 2017 07:43:00 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60546 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751725AbdK0Mm7 (ORCPT ); Mon, 27 Nov 2017 07:42:59 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vARCd5EU007755 for ; Mon, 27 Nov 2017 07:42:58 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2egexy4nnn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Nov 2017 07:42:58 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Nov 2017 12:42:56 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 27 Nov 2017 12:42:52 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vARCgqu235848272; Mon, 27 Nov 2017 12:42:52 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2763852047; Mon, 27 Nov 2017 11:36:16 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.8.170]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 11CF75203F; Mon, 27 Nov 2017 11:36:15 +0000 (GMT) Date: Mon, 27 Nov 2017 14:42:49 +0200 From: Mike Rapoport To: Michal Hocko Cc: guoxuenan , akpm@linux-foundation.org, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, miaoxie@huawei.com, shli@fb.com, aarcange@redhat.com, mgorman@techsingularity.net, kirill.shutemov@linux.intel.com, rientjes@google.com, khandual@linux.vnet.ibm.com, riel@redhat.com Subject: Re: [PATCH] mm,madvise: bugfix of madvise systemcall infinite loop under special circumstances. References: <20171127115318.911-1-guoxuenan@huawei.com> <20171127115847.7b65btmfl762552d@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171127115847.7b65btmfl762552d@dhcp22.suse.cz> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 17112712-0040-0000-0000-000003F2F53E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112712-0041-0000-0000-000025F5CEEB Message-Id: <20171127124248.GA10946@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-27_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711270176 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 27, 2017 at 12:58:47PM +0100, Michal Hocko wrote: > On Mon 27-11-17 19:53:18, guoxuenan wrote: > > From: chenjie > > > > The madvise() system call supported a set of "conventional" advice values, > > the MADV_WILLNEED parameter has possibility of triggering an infinite loop under > > direct access mode(DAX). > > > > Infinite loop situation: > > 1、initial state [ start = vam->vm_start < vam->vm_end < end ]. > > 2、madvise_vma() using MADV_WILLNEED parameter; > > madvise_vma() -> madvise_willneed() -> return 0 && the value of [prev] is not updated. > > > > In function SYSCALL_DEFINE3(madvise,...) > > 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 the value of [prev]. > > > > ======================================================================= > > SYSCALL_DEFINE3(madvise,...) > > { > > [...] > > //start = vam->start => prev=vma->prev > > vma = find_vma_prev(current->mm, start, &prev); > > [...] > > for(;;) > > { > > update [start = vma->vm_start] > > > > con0: if (start >= end) //false always; > > goto out; > > tmp = vma->vm_end; > > > > //do not update [prev] and always return 0; > > error = madvise_willneed(); > > > > con1: if (error) //false always; > > goto out; > > > > //[ vam->vm_start < start = vam->vm_end > update [start = tmp ] > > > > con2: if (start >= end) //false always ; > > goto out; > > > > //because of pointer [prev] did not change,[vma] keep as it was; > > update [ vma = prev->vm_next ] > > } > > [...] > > } > > ======================================================================= > > After the first cycle ;it will always keep > > vam->vm_start < start = vam->vm_end < end && vma = prev->vm_next; > > since Circulation exit conditions (con{0,1,2}) will never meet ,the > > program stuck in infinite loop. > > I find your changelog a bit hard to parse. What would you think about > the following: > " > MADVISE_WILLNEED has always been a noop for DAX (formerly XIP) mappings. > Unfortunatelly madvise_willneed doesn't communicate this information > properly to the generic madvise syscall implementation. The calling > converion is quite subtle there. madvise_vma is supposed to either spelling: "The calling convention" > return an error or update &prev otherwise the main loop will never > advance to the next vma and it will keep looping for ever without a way > to get out of the kernel. > > It seems this has been broken since introduced. Nobody has noticed > because nobody seems to be using MADVISE_WILLNEED on these DAX mappings. > > Fixes: fe77ba6f4f97 ("[PATCH] xip: madvice/fadvice: execute in place") > Cc: stable > " > > > Signed-off-by: chenjie > > Signed-off-by: guoxuenan > > Other than that > Acked-by: Michal Hocko > > > --- > > mm/madvise.c | 4 +--- > > 1 file changed, 1 insertion(+), 3 deletions(-) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index 375cf32..751e97a 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -276,15 +276,14 @@ 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; > > force_shm_swapin_readahead(vma, start, end, > > file->f_mapping); > > return 0; > > @@ -299,7 +298,6 @@ static long madvise_willneed(struct vm_area_struct *vma, > > return 0; > > } > > > > - *prev = vma; > > start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; > > if (end > vma->vm_end) > > end = vma->vm_end; > > -- > > 2.9.5 > > > > -- > Michal Hocko > SUSE Labs > -- Sincerely yours, Mike. From 1585222369662099911@xxx Mon Nov 27 12:30:59 +0000 2017 X-GM-THRID: 1585219652332388182 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread