Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2354322imm; Thu, 7 Jun 2018 09:14:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIh89thG5V4Oq4nr62Rw7cgtQ4U/Jbd1l8eNZj5Xq1hk+Dho6vM+CS/hE8+01CwGcQ5awmd X-Received: by 2002:a62:8a83:: with SMTP id o3-v6mr2388395pfk.12.1528388090043; Thu, 07 Jun 2018 09:14:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528388090; cv=none; d=google.com; s=arc-20160816; b=tLWvVbzBc/6l1k20rISC4OsvDU4uJLS9TDcdvwixJJzLBglNLK45LxoTQNHbWSnN33 Df+6Jf0i4+8ItPKwsNGGPndo6Uom4dl5gxkXVnp6eOgFKDahy6L7LC0FzsgeE2dGfPgM 6oAV8iAVIzfbgC34g4rOkmphqH1PaLlLSXRrKGskNSuO7wPMXFqlM3We3ZSwojg/SzIz 2ErD+1C8DP9LxYVcV+71uUQ9xIDBaS+LsuF4omsYZq4buxMv17wh3baSf3yRDx2lnwVX /cCHmCQMbbyAAz62V6RnrkNiC9NPNpd9KQI9dMB2C7HGgU2eV6mRMDbCCPBerlAdDU6w HQLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Fmctf24CVemfXbgCWk0Y8U92e4+RrjhInCThy2ws4Lk=; b=MUeU1cEmyM4DBqSoM6Du+A8gfMezslOAOMh8Hfs13kwargXvIvLFFXWccWaPz5bB4R 0/Ur+vwn6EpJRmAERz9juYh0jh+0duFyLWYzeKM4twXRcFiTQGS0HyQ7wG9W0BfH98ls 5jf+tHaMHGmegmhnzTH41wCi6g2LZrOyXN/lOIX5oFEDUejEIJhU8a23Lr0MVkFA2BFa Ob881uM7nRGHYroRvHwBL+mLT6DhiVCZPjTNBZFUTlhtnue9wN4b5PAR8ewkT87tdjT+ u1lzqcDAhyZSYVKtcEwN3FEqBUE0ZEQyD+YsZvn6UjJ1jPqU8BGK5A96rBau3jbN6w6w 2hKA== 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 k28-v6si21910675pfh.50.2018.06.07.09.14.36; Thu, 07 Jun 2018 09:14:50 -0700 (PDT) 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 S1753686AbeFGQMl (ORCPT + 99 others); Thu, 7 Jun 2018 12:12:41 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39158 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932962AbeFGOJA (ORCPT ); Thu, 7 Jun 2018 10:09:00 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvay-0005Zr-9s; Thu, 07 Jun 2018 15:08:56 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvax-0002gk-9F; Thu, 07 Jun 2018 15:08:55 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Miao Xie" , "Dan Williams" , "David Rientjes" , "Carsten Otte" , "Shaohua Li" , "Mel Gorman" , "Mike Rapoport" , "Linus Torvalds" , "Anshuman Khandual" , "Kirill A. Shutemov" , "Rik van Riel" , "zhangyi (F)" , "Andrea Arcangeli" , "Michal Hocko" , "guoxuenan" , "Minchan Kim" , "chenjie" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 009/410] mm/madvise.c: fix madvise() infinite loop under special circumstances In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: chenjie commit 6ea8d958a2c95a1d514015d4e29ba21a8c0a1a91 upstream. MADVISE_WILLNEED has always been a noop for DAX (formerly XIP) mappings. Unfortunately madvise_willneed() doesn't communicate this information properly to the generic madvise syscall implementation. The calling convention is quite subtle there. madvise_vma() is supposed to either 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 introduction. Nobody has noticed because nobody seems to be using MADVISE_WILLNEED on these DAX mappings. [mhocko@suse.com: rewrite changelog] Link: http://lkml.kernel.org/r/20171127115318.911-1-guoxuenan@huawei.com Fixes: fe77ba6f4f97 ("[PATCH] xip: madvice/fadvice: execute in place") Signed-off-by: chenjie Signed-off-by: guoxuenan Acked-by: Michal Hocko Cc: Minchan Kim Cc: zhangyi (F) Cc: Miao Xie Cc: Mike Rapoport Cc: Shaohua Li Cc: Andrea Arcangeli Cc: Mel Gorman Cc: Kirill A. Shutemov Cc: David Rientjes Cc: Anshuman Khandual Cc: Rik van Riel Cc: Carsten Otte Cc: Dan Williams Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- --- a/mm/madvise.c +++ b/mm/madvise.c @@ -221,9 +221,9 @@ static long madvise_willneed(struct vm_a { struct file *file = vma->vm_file; + *prev = vma; #ifdef CONFIG_SWAP if (!file || mapping_cap_swap_backed(file->f_mapping)) { - *prev = vma; if (!file) force_swapin_readahead(vma, start, end); else @@ -241,7 +241,6 @@ static long madvise_willneed(struct vm_a return 0; } - *prev = vma; start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; if (end > vma->vm_end) end = vma->vm_end;