Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp458801imm; Wed, 6 Jun 2018 00:03:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIqNeDDWxwVgjS+bt//yYZjKkznjw1D3+1bWSU3cwSqrlz+cwatRs7QnF4mrZ9LSSoX5bj/ X-Received: by 2002:a65:4587:: with SMTP id o7-v6mr1605961pgq.386.1528268613028; Wed, 06 Jun 2018 00:03:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528268612; cv=none; d=google.com; s=arc-20160816; b=MDxXX8wA6DggThkUe1q5OtJtnwNflGI+ZTdpyo6lqBxte5bkz/X4HDHFxYcfNxpg2s PzCWJE9LFP2t6uO1/7vjb71YPw7MedjcNkFZvCZ//fFt+Lq8yFS2firibfYPI8lOvNfl QYCUqZb+GHiJJ4XFoTeq/Fy+SIYPDndb8O2uHXIjGMkJJILbsk0S4kqbFg7hWDMUpN0c KeT+oBagjn00ELNaHPJzpDEMR4s+KTXdGyaExfk9ThCjZvmuGoohjdFBe8jPCh0desZY LrifuOIBr3oUEfLc9e8a/9Sv3VTvdopZBud8XR1AqstNpu80ZWrrcfXM3W+boqeFSMVk h8xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=iRmZmpoEaKhqo6Rb9pFqMkUmpTSiPn7OFTpljF9PmOo=; b=H4nsbDKZlgvh3ia7U9+/1Yfbc8x0VAOxnqSCpAaqpmL8/oOyIc9Q+Mh658HuDqk3/T p4FB7XmHo0GKvZr7tFFU+cXbxa0g/pAAavXVTZHDmFpP81bn3p6P9tm25nxZm4+rd9zy JSsQz//TcxG1y1IEks2L3KoFlL2FfFgPTcMplasmuwS/tNKE4vb3GAfi1IYcHQRXshVi 0zB20EGeqOJ5MhmjT8xvHwzkxBJTHPCAC1ELzcoPmAO/5QbA56xVdrYIXBn1yZ981BIq lg0Ra3dwbhAkbdSwdgigCkUEfIuzRagVqWIjzoZgALWYu+sFI2GrGs8SZt8tap9GAIVz aFGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=XhJK+bbD; dkim=pass header.i=@codeaurora.org header.s=default header.b=jNbwaeIO; 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 j22-v6si11430364pll.353.2018.06.06.00.03.17; Wed, 06 Jun 2018 00:03:32 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=XhJK+bbD; dkim=pass header.i=@codeaurora.org header.s=default header.b=jNbwaeIO; 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 S932301AbeFFHBu (ORCPT + 99 others); Wed, 6 Jun 2018 03:01:50 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56062 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932113AbeFFHBt (ORCPT ); Wed, 6 Jun 2018 03:01:49 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 8B97160263; Wed, 6 Jun 2018 07:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528268508; bh=P2K1eN8Aa4WX+7TfFHFmMjm2xarj/+V2t44oaJEKkVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XhJK+bbDsoDoO4Z/MnGvWPgpHDk1FFLWDydW/JGAo4GxuuOP96N8oeu9T2MMhGZYS GboTDRpcW2KYgGW0187ATFmd8Ziki+NBabEp3T8QhfecONX2akvWwBwsUvSx7oQKbJ 1R8z/k/C6dakAtMt/APn9TtPEiSnV4vovkMKP/+I= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 49B21607C7; Wed, 6 Jun 2018 07:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528268507; bh=P2K1eN8Aa4WX+7TfFHFmMjm2xarj/+V2t44oaJEKkVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jNbwaeIOQTSs2Rodnb7NUgKv6HK5QXt17i8hil1+/jUzYIDSpYNFjRPxFKiHdzTE/ j2mNv3gPU/VbUsxtvmGKWRZWFlkcNOsqWcnz8urs8l3r/IgvyjAGMA0GjngnyLd6JR x77rRVF8DW8oSWy3jqkb9eLkgTT0NWsW9PYkndKU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 49B21607C7 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: will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org Cc: toshi.kani@hpe.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Chintan Pandya Subject: [PATCH v13 3/3] arm64: Implement page table free interfaces Date: Wed, 6 Jun 2018 12:31:21 +0530 Message-Id: <1528268481-19299-4-git-send-email-cpandya@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1528268481-19299-1-git-send-email-cpandya@codeaurora.org> References: <1528268481-19299-1-git-send-email-cpandya@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org arm64 requires break-before-make. Originally, before setting up new pmd/pud entry for huge mapping, in few cases, the modifying pmd/pud entry was still valid and pointing to next level page table as we only clear off leaf PTE in unmap leg. a) This was resulting into stale entry in TLBs (as few TLBs also cache intermediate mapping for performance reasons) b) Also, modifying pmd/pud was the only reference to next level page table and it was getting lost without freeing it. So, page leaks were happening. Implement pud_free_pmd_page() and pmd_free_pte_page() to enforce BBM and also free the leaking page tables. Implementation requires, 1) Clearing off the current pud/pmd entry 2) Invalidation of TLB 3) Freeing of the un-used next level page tables Signed-off-by: Chintan Pandya --- arch/arm64/mm/mmu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 8ae5d7a..65f8627 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) @@ -977,12 +978,51 @@ int pmd_clear_huge(pmd_t *pmdp) return 1; } -int pud_free_pmd_page(pud_t *pud, unsigned long addr) +int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr) { - return pud_none(*pud); + pte_t *table; + pmd_t pmd; + + pmd = READ_ONCE(*pmdp); + + /* No-op for empty entry and WARN_ON for valid entry */ + if (!pmd_present(pmd) || !pmd_table(pmd)) { + VM_WARN_ON(!pmd_table(pmd)); + return 1; + } + + table = pte_offset_kernel(pmdp, addr); + pmd_clear(pmdp); + __flush_tlb_kernel_pgtable(addr); + pte_free_kernel(NULL, table); + return 1; } -int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) +int pud_free_pmd_page(pud_t *pudp, unsigned long addr) { - return pmd_none(*pmd); + pmd_t *table; + pmd_t *pmdp; + pud_t pud; + unsigned long next, end; + + pud = READ_ONCE(*pudp); + + /* No-op for empty entry and WARN_ON for valid entry */ + if (!pud_present(pud) || !pud_table(pud)) { + VM_WARN_ON(!pud_table(pud)); + return 1; + } + + table = pmd_offset(pudp, addr); + pmdp = table; + next = addr; + end = addr + PUD_SIZE; + do { + pmd_free_pte_page(pmdp, next); + } while (pmdp++, next += PMD_SIZE, next != end); + + pud_clear(pudp); + __flush_tlb_kernel_pgtable(addr); + pmd_free(NULL, table); + return 1; } -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project