Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp836860imu; Tue, 11 Dec 2018 08:18:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/VirPIq2Wlqn5rruS/H8JnDAi1L9V4FXHnsWp/xAtTRkWLEIVRyNt6DQhxy8Z7L0ZA9Atid X-Received: by 2002:a63:fc05:: with SMTP id j5mr15404094pgi.434.1544545098265; Tue, 11 Dec 2018 08:18:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544545098; cv=none; d=google.com; s=arc-20160816; b=IRK1BKNyfz4qdyXuFmV8EvrfMjGQ/yVRqDHh/50c2ZApAbCBQGiDd+QfWqKuDx8Dku LdsYKGQZ6PL+XEVfTxuMcei96kUveNe2DHCRPm+dpOOdRo8hrN64xx2QmnilghSVcGAX SzsFOw1TKFkF0W6QXIMkYqCLU4je8kfrCba7Nrwp6CWbhvAIYmJazEIyAPi2EPvbdROB 4PUI1OaX+bzpKu0BrHZjR5UgfxuLpDoCIlsgsPX6ZRtxm4kJO6PIxc+hIXMV/H1J8FU7 6CiaK60HICARZLPnBJq9vg4ndern84ya7wk+GNiHH6I4mgTsgvF72za12GABfVoTKXCo ThPw== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8lvqN7BWRm5sdUI3OJpwk4GtSJ8NO23wMy8DTca1LeA=; b=Scoz6sBqCofahWEb7Ezt2NX+FNeFUXuruWSZAUCzdidmLSmeJksjnVXgmeRt4Q256v caj4SzfVyccIKZAJH+NRqCnVMi4vS3ULLqBiTAUZyVB/dYrFGg0B/qJE1Jqpx9AW6Hxj ig3nehinUfSVlGL8gANTdcxO/JFy47LMKVfB0/6NwHDKFZS7hcJ7z9rXMZ0QpV2D8mDX rdgriTyLnZh/FBJS/rMC2vk3ZrQxx0Qj2R8ukEby7H3/Gk+81wwi6KidYRTVLwJrIq1E VI98xMnzFKYdMWJMVDP8/6iCIkUKPUWzkSX+HqOIrmYCJcquHtgK7CaEpVSQveKKS/Hf G4eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ptogyc4F; 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 4si12186505pgl.192.2018.12.11.08.18.03; Tue, 11 Dec 2018 08:18:18 -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=@kernel.org header.s=default header.b=Ptogyc4F; 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 S1728792AbeLKPsY (ORCPT + 99 others); Tue, 11 Dec 2018 10:48:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:36708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727983AbeLKPsW (ORCPT ); Tue, 11 Dec 2018 10:48:22 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8CEF520989; Tue, 11 Dec 2018 15:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543301; bh=+MHfQRR70XAfTjncgdsYePr26YS5fI7Fxzo56QxNWIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ptogyc4FnAjLgn1NK1DhnXr+xAmq0H5qqBvxXfWnpy7Ce5rX3TPXq9V+mI3C/9nsf 1vBmsVC1SrZc2Y7v3ARb+22RCVWwTAY784SE2uvkUJSF+NSWXUhoGOmRrigZrz1GL0 dwFrl8Z0K2C/1hWE1HP9R7YqTDsnkLLt2yKAyFDU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Simon Guo , "Kirill A. Shutemov" , Alexey Klimov , Eric B Munson , Geert Uytterhoeven , Mel Gorman , Michal Hocko , Shuah Khan , Thierry Reding , Vlastimil Babka , David Rientjes , Andrew Morton , Linus Torvalds , Rafael David Tinoco Subject: [PATCH 4.4 55/91] mm: mlock: avoid increase mm->locked_vm on mlock() when already mlock2(,MLOCK_ONFAULT) Date: Tue, 11 Dec 2018 16:41:14 +0100 Message-Id: <20181211151610.493454417@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Simon Guo commit b155b4fde5bdde9fed439cd1f5ea07173df2ed31 upstream. When one vma was with flag VM_LOCKED|VM_LOCKONFAULT (by invoking mlock2(,MLOCK_ONFAULT)), it can again be populated with mlock() with VM_LOCKED flag only. There is a hole in mlock_fixup() which increase mm->locked_vm twice even the two operations are on the same vma and both with VM_LOCKED flags. The issue can be reproduced by following code: mlock2(p, 1024 * 64, MLOCK_ONFAULT); //VM_LOCKED|VM_LOCKONFAULT mlock(p, 1024 * 64); //VM_LOCKED Then check the increase VmLck field in /proc/pid/status(to 128k). When vma is set with different vm_flags, and the new vm_flags is with VM_LOCKED, it is not necessarily be a "new locked" vma. This patch corrects this bug by prevent mm->locked_vm from increment when old vm_flags is already VM_LOCKED. Link: http://lkml.kernel.org/r/1472554781-9835-3-git-send-email-wei.guo.simon@gmail.com Signed-off-by: Simon Guo Acked-by: Kirill A. Shutemov Cc: Alexey Klimov Cc: Eric B Munson Cc: Geert Uytterhoeven Cc: Mel Gorman Cc: Michal Hocko Cc: Shuah Khan Cc: Simon Guo Cc: Thierry Reding Cc: Vlastimil Babka Cc: David Rientjes Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Cc: Rafael David Tinoco Signed-off-by: Greg Kroah-Hartman --- mm/mlock.c | 3 +++ 1 file changed, 3 insertions(+) --- a/mm/mlock.c +++ b/mm/mlock.c @@ -504,6 +504,7 @@ static int mlock_fixup(struct vm_area_st int nr_pages; int ret = 0; int lock = !!(newflags & VM_LOCKED); + vm_flags_t old_flags = vma->vm_flags; if (newflags == vma->vm_flags || (vma->vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm)) @@ -538,6 +539,8 @@ success: nr_pages = (end - start) >> PAGE_SHIFT; if (!lock) nr_pages = -nr_pages; + else if (old_flags & VM_LOCKED) + nr_pages = 0; mm->locked_vm += nr_pages; /*