From patchwork Thu Feb 11 09:28:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 581782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B288C14018C for ; Thu, 11 Feb 2016 20:29:29 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTnZ1-0002aI-Nh; Thu, 11 Feb 2016 09:29:27 +0000 Received: from smtprelay4.synopsys.com ([198.182.47.9] helo=smtprelay.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aTnYz-0002Wj-Ls for linux-snps-arc@lists.infradead.org; Thu, 11 Feb 2016 09:29:26 +0000 Received: from us02secmta2.synopsys.com (us02secmta2.synopsys.com [10.12.235.98]) by smtprelay.synopsys.com (Postfix) with ESMTP id 65D4824E0E3E; Thu, 11 Feb 2016 01:29:08 -0800 (PST) Received: from us02secmta2.internal.synopsys.com (us02secmta2.internal.synopsys.com [127.0.0.1]) by us02secmta2.internal.synopsys.com (Service) with ESMTP id 58D3D55F15; Thu, 11 Feb 2016 01:29:08 -0800 (PST) Received: from mailhost.synopsys.com (unknown [10.13.184.66]) by us02secmta2.internal.synopsys.com (Service) with ESMTP id EC71755F14; Thu, 11 Feb 2016 01:29:07 -0800 (PST) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id D1E63B00; Thu, 11 Feb 2016 01:29:07 -0800 (PST) Received: from US01WXQAHTC1.internal.synopsys.com (us01wxqahtc1.internal.synopsys.com [10.12.238.230]) by mailhost.synopsys.com (Postfix) with ESMTP id B2FDCAF6; Thu, 11 Feb 2016 01:29:07 -0800 (PST) Received: from IN01WEHTCB.internal.synopsys.com (10.144.199.106) by US01WXQAHTC1.internal.synopsys.com (10.12.238.230) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 11 Feb 2016 01:29:07 -0800 Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.103) by IN01WEHTCB.internal.synopsys.com (10.144.199.105) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 11 Feb 2016 14:59:05 +0530 Received: from vineet-E7440.internal.synopsys.com (10.12.197.208) by IN01WEHTCA.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 11 Feb 2016 14:59:04 +0530 From: Vineet Gupta To: Andrew Morton , "Kirill A. Shutemov" Subject: [PATCH 1/2] mm, thp: refactor generic deposit/withdraw routines for wider usage Date: Thu, 11 Feb 2016 14:58:26 +0530 Message-ID: <1455182907-15445-2-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455182907-15445-1-git-send-email-vgupta@synopsys.com> References: <1455182907-15445-1-git-send-email-vgupta@synopsys.com> MIME-Version: 1.0 X-Originating-IP: [10.12.197.208] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160211_012925_732526_FC98AAA5 X-CRM114-Status: GOOD ( 12.58 ) X-Spam-Score: -2.2 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [198.182.47.9 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [198.182.47.9 listed in wl.mailspike.net] -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Andrea Arcangeli , Vineet Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Aneesh Kumar K.V" , Martin Schwidefsky , Alex Thorlton , linux-snps-arc@lists.infradead.org, "David S. Miller" , Gerald Schaefer Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Generic pgtable_trans_huge_deposit()/pgtable_trans_huge_withdraw() assume pgtable_t to be struct page * which is not true for all arches. Thus arc, s390, sparch end up with their own copies despite no special hardware requirements (unlike powerpc). It seems massaging the code a bit can make it reusbale. - Use explicit casts to (struct page *). For existing users, this should be semantically no-op for existing users - The only addition is zero'ing out of page->lru which for arc leaves a stray entry in pgtable_t cause mm spew when such pgtable is freed. | huge_memory: BUG: failure at | ../mm/huge_memory.c:1858/__split_huge_page_map()! | CPU: 0 PID: 901 Comm: bw_mem Not tainted 4.4.0-00015-g0569c1459cfa-dirty | | Stack Trace: | arc_unwind_core.constprop.1+0x94/0x104 | split_huge_page_to_list+0x5c0/0x920 | __split_huge_page_pmd+0xc8/0x1b4 | vma_adjust_trans_huge+0x104/0x1c8 | vma_adjust+0xf8/0x6d8 | __split_vma.isra.40+0xf8/0x174 | do_munmap+0x360/0x428 | SyS_munmap+0x28/0x44 Cc: Kirill A. Shutemov Cc: Aneesh Kumar K.V Cc: Andrea Arcangeli Cc: Andrew Morton Cc: David S. Miller Cc: Alex Thorlton Cc: Gerald Schaefer Cc: Martin Schwidefsky Cc: linux-snps-arc@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-arch@vger.kernel.org Signed-off-by: Vineet Gupta --- mm/pgtable-generic.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c index 75664ed7e3ab..c9f2f6f8c7bb 100644 --- a/mm/pgtable-generic.c +++ b/mm/pgtable-generic.c @@ -155,13 +155,17 @@ void pmdp_splitting_flush(struct vm_area_struct *vma, unsigned long address, void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp, pgtable_t pgtable) { + struct page *new = (struct page *)pgtable; + struct page *head; + assert_spin_locked(pmd_lockptr(mm, pmdp)); /* FIFO */ - if (!pmd_huge_pte(mm, pmdp)) - INIT_LIST_HEAD(&pgtable->lru); + head = (struct page *)pmd_huge_pte(mm, pmdp); + if (!head) + INIT_LIST_HEAD(&new->lru); else - list_add(&pgtable->lru, &pmd_huge_pte(mm, pmdp)->lru); + list_add(&new->lru, &head->lru); pmd_huge_pte(mm, pmdp) = pgtable; } #endif @@ -170,20 +174,23 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp, /* no "address" argument so destroys page coloring of some arch */ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp) { - pgtable_t pgtable; + struct page *page; assert_spin_locked(pmd_lockptr(mm, pmdp)); + page = (struct page *)pmd_huge_pte(mm, pmdp); + /* FIFO */ - pgtable = pmd_huge_pte(mm, pmdp); - if (list_empty(&pgtable->lru)) + if (list_empty(&page->lru)) pmd_huge_pte(mm, pmdp) = NULL; else { - pmd_huge_pte(mm, pmdp) = list_entry(pgtable->lru.next, - struct page, lru); - list_del(&pgtable->lru); + pmd_huge_pte(mm, pmdp) = (pgtable_t) list_entry(page->lru.next, + struct page, lru); + list_del(&page->lru); } - return pgtable; + + memset(&page->lru, 0, sizeof(page->lru)); + return (pgtable_t)page; } #endif