From patchwork Mon Mar 19 12:40:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chintan Pandya X-Patchwork-Id: 10292285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F67C60385 for ; Mon, 19 Mar 2018 12:42:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BA5326220 for ; Mon, 19 Mar 2018 12:42:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2DDF281E1; Mon, 19 Mar 2018 12:42:49 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6BF6026220 for ; Mon, 19 Mar 2018 12:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=sClIc1R7GR7wWqORP63LaYkZjMhmke6VBZ4Gjum5KZc=; b=mN1W3odUVN0BvRBtklhEpRWEqu fktpCnO3TWr8dtLJgsUZZIYYDpP0AjqRjxhnx9GX3XIlJRzeM3F0mouUrk+UWRRYtuxvYq/nX+mEY Hm7FGHY5Th4h06XCFNdR3OQL43+nn6AtWQt6tROhR+KbHS9b91k4QOOjYJ5ZcT4tX6oPQRpESNQao fUVGiI3H/rGHdEMyX+3nodjPVYiFFlmR26uNm/xzds/GRnMrjrI9sWI+KYaa+/b4jUZ7pTqQSf1qV rRiTu7m3xxDF263+qNCsVS/CXT806OQ79ULxOQPrjdx6aKm9PfDdrIGTtyKFYLFf1dHPkaglP/NE7 VJIN8cjg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1exu7h-0007dj-DK; Mon, 19 Mar 2018 12:42:45 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1exu6c-000707-Tm for linux-arm-kernel@lists.infradead.org; Mon, 19 Mar 2018 12:41:45 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5B1AF60C67; Mon, 19 Mar 2018 12:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521463288; bh=fW0NgLF04tXG6F3HOe3P6dXgrVXLzA+u/6aPeGpSF5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ob0hQ4zdTqpyUmHG+HEELn8PGEEFNd1q/erJ+WiKfO0d2tFYBT+nQat5wsyPlRb0X HrefwWlUuxE5HE3lvpnzIkLzCLaa4Z8ONFq9qr3I+hfZ8Scgk69YLjES+WNLuaVBHH oK2IHJwC7LXf0RCzy5mBKymn5oBSuKEVhA1mBxUI= Received: from cpandya-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cpandya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C847B60C67; Mon, 19 Mar 2018 12:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521463287; bh=fW0NgLF04tXG6F3HOe3P6dXgrVXLzA+u/6aPeGpSF5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MrMXWP7RLk+hCevrnAcS41T0tDq9c79bY9QMHISqzyu18HIZDEhIrlEPKIATrimXX sYvqYU3zH5lxKv1UQP2hHBmwKdGa4cn9WYVP/Wr2EkXlFNUa+0Ugz92zEEHIrsk1rY sM+nos5xbNOTlxUcV/t4HB4WwEzX89xcmp1Q6Z+Y= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C847B60C67 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cpandya@codeaurora.org From: Chintan Pandya To: catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com Subject: [PATCH v3 2/3] arm64: Implement page table free interfaces Date: Mon, 19 Mar 2018 18:10:55 +0530 Message-Id: <1521463256-19858-3-git-send-email-cpandya@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1521463256-19858-1-git-send-email-cpandya@codeaurora.org> References: <1521463256-19858-1-git-send-email-cpandya@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180319_054140_150260_CCA6670D X-CRM114-Status: GOOD ( 15.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, toshi.kani@hpe.com, arnd@arndb.de, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, kristina.martsenko@arm.com, takahiro.akashi@linaro.org, james.morse@arm.com, Chintan Pandya , tglx@linutronix.de, akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Implement pud_free_pmd_page() and pmd_free_pte_page(). Implementation requires, 1) Freeing of the un-used next level page tables 2) Clearing off the current pud/pmd entry 3) Invalidate TLB which could have previously valid but not stale entry Signed-off-by: Chintan Pandya --- arch/arm64/mm/mmu.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index da98828..c70f139 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -45,6 +45,7 @@ #include #include #include +#include #define NO_BLOCK_MAPPINGS BIT(0) #define NO_CONT_MAPPINGS BIT(1) @@ -975,10 +976,35 @@ int pmd_clear_huge(pmd_t *pmdp) int pud_free_pmd_page(pud_t *pud, unsigned long addr) { - return pud_none(*pud); + pmd_t *pmd; + int i; + + pmd = __va(pud_val(*pud)); + if (pud_val(*pud)) { + for (i = 0; i < PTRS_PER_PMD; i++) + pmd_free_pte_page(&pmd[i], addr + (i * PMD_SIZE)); + + free_page((unsigned long) pmd); + pud_clear(pud); + flush_tlb_kernel_range(addr, addr + PUD_SIZE); + } + return 1; } int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) { - return pmd_none(*pmd); + if (pmd_val(*pmd)) { + free_page((unsigned long)__va(pmd_val(*pmd))); + + pmd_clear(pmd); + /* + * FIXME: __flush_tlb_pgtable(&init_mm, addr) is + * ideal candidate here, which exactly + * flushes intermediate pgtables. But, + * this is broken (evident from tests). + * So, use safe TLB op unless that is fixed. + */ + flush_tlb_kernel_range(addr, addr + PMD_SIZE); + } + return 1; }