From patchwork Wed Mar 18 15:16:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 6040891 Return-Path: X-Original-To: patchwork-linux-parisc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0D3629F314 for ; Wed, 18 Mar 2015 15:16:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 30BEF2042A for ; Wed, 18 Mar 2015 15:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 506A020411 for ; Wed, 18 Mar 2015 15:16:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753113AbbCRPQ4 (ORCPT ); Wed, 18 Mar 2015 11:16:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46266 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750896AbbCRPQ4 (ORCPT ); Wed, 18 Mar 2015 11:16:56 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2IFGjIh024028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 18 Mar 2015 11:16:45 -0400 Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2IFGhBM003999 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 18 Mar 2015 11:16:44 -0400 Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id t2IFGhaE030139; Wed, 18 Mar 2015 11:16:43 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id t2IFGguU030135; Wed, 18 Mar 2015 11:16:43 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Wed, 18 Mar 2015 11:16:42 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: "Kirill A. Shutemov" , linux-mm@kvack.org, linux-parisc@vger.kernel.org cc: jejb@parisc-linux.org, dave.anglin@bell.net Subject: [PATCH] mm: don't count preallocated pmds Message-ID: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Here I'm sending a patch that fixes numerous "BUG: non-zero nr_pmds on freeing mm: -1" errors on 64-bit PA-RISC kernel. I think the patch posted here http://www.spinics.net/lists/linux-parisc/msg05981.html is incorrect, it wouldn't work if the affected address range is freed and allocated multiple times. - 1. alloc pgd with built-in pmd, the count of pmds is 1 - 2. free the range covered by the built-in pmd, the count of pmds is 0, but the built-in pmd is still present - 3. alloc some memory in the range affected by the built-in pmd, the count of pmds is still 0 - 4. free the range covered by the built-in pmd, the counter underflows to -1 Mikulas From: Mikulas Patocka The patch dc6c9a35b66b520cf67e05d8ca60ebecad3b0479 that counts pmds allocated for a process introduced a bug on 64-bit PA-RISC kernels. There are many "BUG: non-zero nr_pmds on freeing mm: -1" messages. The PA-RISC architecture preallocates one pmd with each pgd. This preallocated pmd can never be freed - pmd_free does nothing when it is called with this pmd. When the kernel attempts to free this preallocated pmd, it decreases the count of allocated pmds. The result is that the counter underflows and this error is reported. This patch fixes the bug by introducing a macro pmd_preallocated and making sure that the counter is not decremented when this preallocated pmd is freed. Signed-off-by: Mikulas Patocka --- arch/parisc/include/asm/pgalloc.h | 2 ++ mm/memory.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-parisc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-4.0-rc4/arch/parisc/include/asm/pgalloc.h =================================================================== --- linux-4.0-rc4.orig/arch/parisc/include/asm/pgalloc.h 2015-03-18 15:31:10.000000000 +0100 +++ linux-4.0-rc4/arch/parisc/include/asm/pgalloc.h 2015-03-18 15:33:20.000000000 +0100 @@ -81,6 +81,8 @@ static inline void pmd_free(struct mm_st free_pages((unsigned long)pmd, PMD_ORDER); } +#define pmd_preallocated(pmd) (pmd_flag(*(pmd)) & PxD_FLAG_ATTACHED) + #else /* Two Level Page Table Support for pmd's */ Index: linux-4.0-rc4/mm/memory.c =================================================================== --- linux-4.0-rc4.orig/mm/memory.c 2015-03-18 15:30:42.000000000 +0100 +++ linux-4.0-rc4/mm/memory.c 2015-03-18 15:32:33.000000000 +0100 @@ -427,8 +427,11 @@ static inline void free_pmd_range(struct pmd = pmd_offset(pud, start); pud_clear(pud); +#ifdef pmd_preallocated + if (!pmd_preallocated(pmd)) +#endif + mm_dec_nr_pmds(tlb->mm); pmd_free_tlb(tlb, pmd, start); - mm_dec_nr_pmds(tlb->mm); } static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,