Received: by 10.192.165.148 with SMTP id m20csp2543136imm; Sun, 22 Apr 2018 09:13:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx48M6gOJdL1oNFKntqtmGJBz/jyBuKb9E1/2e4sp9YPl8puzjgwtaDVCkwi+GCLJgJiqN/GM X-Received: by 2002:a17:902:145:: with SMTP id 63-v6mr17799919plb.332.1524413584299; Sun, 22 Apr 2018 09:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524413584; cv=none; d=google.com; s=arc-20160816; b=OfxiSoDo0EnCb8l4XUIUPsZUeIpsXPmQd4a1nQc7nf+a7eh1nwXIltBvRAyNROxhqo m31ajuhhCl24/ojK3n1poSxCWme4rmVkIYDo2ieD6GicHIdoVMjp3A4hoEX6jbJAzezr ChYxBwG8+1OV8wzMPq695nYocc/hjYMwl37dbK0rgaTF6GsS1kWpPut7vldfBG1Ova26 FmDEnZLZ6zPgXhH7HFNnTXi8wGn9WHcEiREXv1buaz36LoddOKWP2HEOCw/uE0+hAPS/ MakZUnUIVT5gbZMM6ss/PJ8UHgU6qPvZ18S7JSa//Y4+nqaX9Z2SFRkl8XrxjlUEfWO5 fh1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jLEs9OF0b2oyXvGVJtJjxOLz+8IlltuKuaib9B4xrbI=; b=W5HJo7xY3RDLHXwhf9P26vQKgo60sJkxVU/wiO/mOrkZNz2/5D/SJvvjSHzhfY1fyw 3FGAh0Ef4qwOIPUMbq851+3ObHtk2IkDUzHqaPEGsZswCleql+ztiCtqRJvX2PhsPH1k LR7CSGGjAGRA60kUz+kQKkE75t7fchhIrkDUJsxyh3iAKh7BAyAV1lNXIZut9XdEoXI0 IxzUhSL85YfxGmouvzieZ5CeS0zGLcvcP3swMZ+pFbjisrcw3P3w0mZKlxfs1VwriTN0 vgWdIqNH5AcLrcPxcgZbm2t88wWL6WC+emhXHJ2x6WE8BJuLfW8u4VCfTHjbiGu/rSET nvsg== 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 l5-v6si4392014pli.409.2018.04.22.09.12.50; Sun, 22 Apr 2018 09:13:04 -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 S1754037AbeDVQLt (ORCPT + 99 others); Sun, 22 Apr 2018 12:11:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44832 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753623AbeDVNzx (ORCPT ); Sun, 22 Apr 2018 09:55:53 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E9A638FF; Sun, 22 Apr 2018 13:55:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Claudio Imbrenda , Andrew Morton , Andrea Arcangeli , Minchan Kim , "Kirill A. Shutemov" , Hugh Dickins , Christian Borntraeger , Gerald Schaefer , Linus Torvalds Subject: [PATCH 4.16 008/196] mm/ksm.c: fix inconsistent accounting of zero pages Date: Sun, 22 Apr 2018 15:50:28 +0200 Message-Id: <20180422135104.636269827@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Claudio Imbrenda commit a38c015f3156895b07e71d4e4414289f8a3b2745 upstream. When using KSM with use_zero_pages, we replace anonymous pages containing only zeroes with actual zero pages, which are not anonymous. We need to do proper accounting of the mm counters, otherwise we will get wrong values in /proc and a BUG message in dmesg when tearing down the mm. Link: http://lkml.kernel.org/r/1522931274-15552-1-git-send-email-imbrenda@linux.vnet.ibm.com Fixes: e86c59b1b1 ("mm/ksm: improve deduplication of zero pages with colouring") Signed-off-by: Claudio Imbrenda Reviewed-by: Andrew Morton Cc: Andrea Arcangeli Cc: Minchan Kim Cc: Kirill A. Shutemov Cc: Hugh Dickins Cc: Christian Borntraeger Cc: Gerald Schaefer Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/ksm.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1131,6 +1131,13 @@ static int replace_page(struct vm_area_s } else { newpte = pte_mkspecial(pfn_pte(page_to_pfn(kpage), vma->vm_page_prot)); + /* + * We're replacing an anonymous page with a zero page, which is + * not anonymous. We need to do proper accounting otherwise we + * will get wrong values in /proc, and a BUG message in dmesg + * when tearing down the mm. + */ + dec_mm_counter(mm, MM_ANONPAGES); } flush_cache_page(vma, addr, pte_pfn(*ptep));