From patchwork Wed Nov 14 22:22:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10683159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EDB4014DB for ; Wed, 14 Nov 2018 22:24:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFA862AEA2 for ; Wed, 14 Nov 2018 22:24:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3B9F2BEA4; Wed, 14 Nov 2018 22:24:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36A222AEA2 for ; Wed, 14 Nov 2018 22:24:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C0F56B000A; Wed, 14 Nov 2018 17:24:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 470A06B000C; Wed, 14 Nov 2018 17:24:11 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 361896B000D; Wed, 14 Nov 2018 17:24:11 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id E99B66B000A for ; Wed, 14 Nov 2018 17:24:10 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id o28-v6so11121782pfk.10 for ; Wed, 14 Nov 2018 14:24:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=/AcXeb9HEa5yfVGQaqQYpFROH+bxrnWiTzFcDXZxipA=; b=rSXy5j54MAby6XFNiBqBBHY1brR/CSjJLn/Wv6cv3KQgf7a0mBZcZIKrieSuoYabW9 obLbFLvvj2XpHl8z1ON7jMHl8HlHh5jvWlTzxbKzhhz06Ya8U021TC2LHN3NJuKv7Hf9 JgI/mqSXsErKUdRGBpme/W4IVCmDEGkrhip0R/mT9Ztmc/lW3VQWYx2qzitdoyZtrTXB UEaDDRxfDy3Xjg6mSVgquHuMP7YhyWkX518+h9DIwesKOUUYN9XWmKSzQGaIWBOqwnSK 3Zd8vJtjY7GvlrEI2wOyiORlUcmgJdmgBqyGMfLP445yVLZzpxJ6aVKUcjkMvI8yO548 F/lg== X-Gm-Message-State: AGRZ1gJKaS2SBTh2kRDh0aAgih3NZiK5NczjbBWVYWjnmTzHCUiyzlf6 s2/XHWMrgISc0IykQTyvNh40Hu+esHX22QOAtAWjyVTjUjtdF6QgAJYbzZxJgGsxW8a/QxQy4JF SSYzOnQcBpET33S8jYRSJ1J0OJ+T8lM3w1r6bS4mDkXviWbPd3L5eFK7EeRPkOAIZEw== X-Received: by 2002:a62:3948:: with SMTP id g69mr3849280pfa.114.1542234250528; Wed, 14 Nov 2018 14:24:10 -0800 (PST) X-Google-Smtp-Source: AJdET5cPcbvyHj1r662so+RVH2WQqMGfZiFb6AI+wexHjCdv/AZE0pknp3rqcsLNQ7ikI9VHPZr7 X-Received: by 2002:a62:3948:: with SMTP id g69mr3849084pfa.114.1542234245783; Wed, 14 Nov 2018 14:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542234245; cv=none; d=google.com; s=arc-20160816; b=aBAGFRsAgqs4zwvR/uDZPhrH3gdxp5IJ1DLqCpwtet53iJVPB0/Jn8bs9nsSH+L9JQ VCABgRMDs3BzXbk1OpzzL//tVlAFOr3/E7DPKuZbrgbAwiOU8v75NtTcA6Vglvfj/Smt 8L1OMaXAoha2K4yDpSzTYzyaCrbhJcVLAMMEOMcuVyoNIBS9dunXTYrpzfgygN/vDs2N Ixqi4BxIZjjiaIp5v96p35FXJcyGxs9r1bXEKCvJeeVGrwum98Kp6L7+Etjwu9c/xrPA SWlONgxAfmfG01AdinfbynrauBGV8bMwzOWYG/D79MncDu84sGHtOAa3yVeb67g6IXQO 6JBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/AcXeb9HEa5yfVGQaqQYpFROH+bxrnWiTzFcDXZxipA=; b=WqoA10ng+wcdLwao+lAGN8l4g7gANAjhEZqxZniXcmaVVHNL6PhM59rGvH49ecuPk0 VnaJ+wzayyEWQSukCxPZbgC6mow/pztd3tXqJPERgUvoqDXCeAVVDxF3G0dOwOZMoUA1 aIRIMPiTG/rNcOSRbyYjpaW6RYRbkQhxueHvlye8bGg8I5Q+LH0Tq4KdKHTD/VQFrk6+ 987hsmQNtusOhvkL7ZjxjoL/500lvBG9KhabiA0DLQ5dFlyUhwdH6TpzkpQ8fOpWJPPj /4C6wsc+ylPvfexvSD9pXTR9fAoL55Wk2UjEuwLq4i/HrKnygDr2GEwriPqQuZgK3isI WRqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K5b6YvkI; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id u13si4037880plq.268.2018.11.14.14.24.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:24:05 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K5b6YvkI; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 509B622523; Wed, 14 Nov 2018 22:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542234245; bh=q6jVL8WDWM+vfR1uGUfPYvjO6H+/r0sOMkjRsFgyH4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5b6YvkI3gFHaRcG3vKOsuj0hWYtkAeVFInkj4fJFbHcX9jOx4aik0f0VrSAKZyix RqIkJQk5yI2mr8LeXoOhyIZykrAEf6uUe9PHhKQd3igQh+m1l7PGkg0cyoLB113D4I XeCpK53MkLwV9ZOqBYA7CbEMBtVmnKvDNbNwuc4w= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Martin Schwidefsky , Sasha Levin , linux-s390@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.18 08/59] s390/mm: fix mis-accounting of pgtable_bytes Date: Wed, 14 Nov 2018 17:22:40 -0500 Message-Id: <20181114222335.99339-8-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114222335.99339-1-sashal@kernel.org> References: <20181114222335.99339-1-sashal@kernel.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Schwidefsky [ Upstream commit e12e4044aede97974f2222eb7f0ed726a5179a32 ] In case a fork or a clone system fails in copy_process and the error handling does the mmput() at the bad_fork_cleanup_mm label, the following warning messages will appear on the console: BUG: non-zero pgtables_bytes on freeing mm: 16384 The reason for that is the tricks we play with mm_inc_nr_puds() and mm_inc_nr_pmds() in init_new_context(). A normal 64-bit process has 3 levels of page table, the p4d level and the pud level are folded. On process termination the free_pud_range() function in mm/memory.c will subtract 16KB from pgtable_bytes with a mm_dec_nr_puds() call, but there actually is not really a pud table. One issue with this is the fact that pgtable_bytes is usually off by a few kilobytes, but the more severe problem is that for a failed fork or clone the free_pgtables() function is not called. In this case there is no mm_dec_nr_puds() or mm_dec_nr_pmds() that go together with the mm_inc_nr_puds() and mm_inc_nr_pmds in init_new_context(). The pgtable_bytes will be off by 16384 or 32768 bytes and we get the BUG message. The message itself is purely cosmetic, but annoying. To fix this override the mm_pmd_folded, mm_pud_folded and mm_p4d_folded function to check for the true size of the address space. Reported-by: Li Wang Tested-by: Li Wang Signed-off-by: Martin Schwidefsky Signed-off-by: Sasha Levin --- arch/s390/include/asm/mmu_context.h | 5 ----- arch/s390/include/asm/pgalloc.h | 6 +++--- arch/s390/include/asm/pgtable.h | 18 ++++++++++++++++++ arch/s390/include/asm/tlb.h | 6 +++--- arch/s390/mm/pgalloc.c | 1 + 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/arch/s390/include/asm/mmu_context.h b/arch/s390/include/asm/mmu_context.h index d16bc79c30bb..02331ce22bf4 100644 --- a/arch/s390/include/asm/mmu_context.h +++ b/arch/s390/include/asm/mmu_context.h @@ -44,8 +44,6 @@ static inline int init_new_context(struct task_struct *tsk, mm->context.asce_limit = STACK_TOP_MAX; mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH | _ASCE_USER_BITS | _ASCE_TYPE_REGION3; - /* pgd_alloc() did not account this pud */ - mm_inc_nr_puds(mm); break; case -PAGE_SIZE: /* forked 5-level task, set new asce with new_mm->pgd */ @@ -61,9 +59,6 @@ static inline int init_new_context(struct task_struct *tsk, /* forked 2-level compat task, set new asce with new mm->pgd */ mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH | _ASCE_USER_BITS | _ASCE_TYPE_SEGMENT; - /* pgd_alloc() did not account this pmd */ - mm_inc_nr_pmds(mm); - mm_inc_nr_puds(mm); } crst_table_init((unsigned long *) mm->pgd, pgd_entry_type(mm)); return 0; diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h index f0f9bcf94c03..5ee733720a57 100644 --- a/arch/s390/include/asm/pgalloc.h +++ b/arch/s390/include/asm/pgalloc.h @@ -36,11 +36,11 @@ static inline void crst_table_init(unsigned long *crst, unsigned long entry) static inline unsigned long pgd_entry_type(struct mm_struct *mm) { - if (mm->context.asce_limit <= _REGION3_SIZE) + if (mm_pmd_folded(mm)) return _SEGMENT_ENTRY_EMPTY; - if (mm->context.asce_limit <= _REGION2_SIZE) + if (mm_pud_folded(mm)) return _REGION3_ENTRY_EMPTY; - if (mm->context.asce_limit <= _REGION1_SIZE) + if (mm_p4d_folded(mm)) return _REGION2_ENTRY_EMPTY; return _REGION1_ENTRY_EMPTY; } diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 5ab636089c60..960cf51e9d43 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -483,6 +483,24 @@ static inline int is_module_addr(void *addr) _REGION_ENTRY_PROTECT | \ _REGION_ENTRY_NOEXEC) +static inline bool mm_p4d_folded(struct mm_struct *mm) +{ + return mm->context.asce_limit <= _REGION1_SIZE; +} +#define mm_p4d_folded(mm) mm_p4d_folded(mm) + +static inline bool mm_pud_folded(struct mm_struct *mm) +{ + return mm->context.asce_limit <= _REGION2_SIZE; +} +#define mm_pud_folded(mm) mm_pud_folded(mm) + +static inline bool mm_pmd_folded(struct mm_struct *mm) +{ + return mm->context.asce_limit <= _REGION3_SIZE; +} +#define mm_pmd_folded(mm) mm_pmd_folded(mm) + static inline int mm_has_pgste(struct mm_struct *mm) { #ifdef CONFIG_PGSTE diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h index 457b7ba0fbb6..b31c779cf581 100644 --- a/arch/s390/include/asm/tlb.h +++ b/arch/s390/include/asm/tlb.h @@ -136,7 +136,7 @@ static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, unsigned long address) { - if (tlb->mm->context.asce_limit <= _REGION3_SIZE) + if (mm_pmd_folded(tlb->mm)) return; pgtable_pmd_page_dtor(virt_to_page(pmd)); tlb_remove_table(tlb, pmd); @@ -152,7 +152,7 @@ static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, static inline void p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d, unsigned long address) { - if (tlb->mm->context.asce_limit <= _REGION1_SIZE) + if (mm_p4d_folded(tlb->mm)) return; tlb_remove_table(tlb, p4d); } @@ -167,7 +167,7 @@ static inline void p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d, static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, unsigned long address) { - if (tlb->mm->context.asce_limit <= _REGION2_SIZE) + if (mm_pud_folded(tlb->mm)) return; tlb_remove_table(tlb, pud); } diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c index 76d89ee8b428..814f26520aa2 100644 --- a/arch/s390/mm/pgalloc.c +++ b/arch/s390/mm/pgalloc.c @@ -101,6 +101,7 @@ int crst_table_upgrade(struct mm_struct *mm, unsigned long end) mm->context.asce_limit = _REGION1_SIZE; mm->context.asce = __pa(mm->pgd) | _ASCE_TABLE_LENGTH | _ASCE_USER_BITS | _ASCE_TYPE_REGION2; + mm_inc_nr_puds(mm); } else { crst_table_init(table, _REGION1_ENTRY_EMPTY); pgd_populate(mm, (pgd_t *) table, (p4d_t *) pgd);