From patchwork Wed Mar 14 08:48:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chintan Pandya X-Patchwork-Id: 10281665 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 4ACA7602C2 for ; Wed, 14 Mar 2018 08:50:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AAF32874F for ; Wed, 14 Mar 2018 08:50:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F0B528794; Wed, 14 Mar 2018 08:50:43 +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 A62852874F for ; Wed, 14 Mar 2018 08:50:42 +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=Nb6qC71PnD9xzf5QRFU21RgHl/GFF+liFuOnE/sUCQc=; b=cW3+qCd8+h0KIEcvqA3odfq+M7 OAqrIFIpQSQSwghKVFDvV8J3+0EqV4n8LVx+p7GdHTJaJaIZXP2VKWW0kN4dWfW1zGVdnNJGAE+we W8HzOPoPH8d7Pz3rHlAOChHgCwVmZ3yCkoWIOCuNWXxeUOS1zGLeFFQ4R5BPO7iUzG2abugWMitZk hgNLWGGhjhWj7XimKQTw9U8jkDsNGFFAFc5YpQAHwk3ao8bHFwLuFot53vaq4r+IXswUfC4HRzuOe XqcdXkmluSOs3FFsK/ljOCrD0ijcI7QoxSgTn+8BRpjCeyw6yzYQr98HWoFMjYiyG9DqVYSHixdQ0 tYr00qSw==; 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 1ew27I-00061T-US; Wed, 14 Mar 2018 08:50:36 +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 1ew25m-0003wD-Hv for linux-arm-kernel@lists.infradead.org; Wed, 14 Mar 2018 08:49:14 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 36E7360853; Wed, 14 Mar 2018 08:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521017339; bh=wTZVOxSLTNRRn1rwz2sMDTZVvRwAVp5H16e5T/d2FQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2ga2Wxyf8wXFXe2rsm83uPvXiwVIzDPJMZn09Srg+CNNAlEOFljRUlhbOQmVYlM2 1c7ywxIpbW+6OPnybIulZ94lulFOWNvDP5beDZM1h6a9dWQ4JyXuvLCZ/Ymoc0jFS4 cHqh0FtrW3hx1TfAqosl1pccbcFYre9mU4g9036k= 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 E059A609F3; Wed, 14 Mar 2018 08:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521017338; bh=wTZVOxSLTNRRn1rwz2sMDTZVvRwAVp5H16e5T/d2FQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TeJpI14Pi/A/pvILvuAbsU5S8EwUdud0xVMbk9daN7fgHi8HGCL9JAnqH5ABF4oxl /vMxuaxTyghFbBCesESeL87/UwFqpZDcHIg+DqGlMQdLBg3+kIZA8aP4B6DXPhy1gG kocl+XtW8g3GXe4dxFcCbesZnVJrVr0whnjYVIYU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E059A609F3 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, arnd@arndb.de Subject: [PATCH v1 3/4] arm64: Fix the page leak in pud/pmd_set_huge Date: Wed, 14 Mar 2018 14:18:24 +0530 Message-Id: <1521017305-28518-4-git-send-email-cpandya@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1521017305-28518-1-git-send-email-cpandya@codeaurora.org> References: <1521017305-28518-1-git-send-email-cpandya@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180314_014903_421650_76F12A7C X-CRM114-Status: GOOD ( 11.92 ) 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: mark.rutland@arm.com, linux-arch@vger.kernel.org, toshi.kani@hpe.com, 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 While setting huge page, we need to take care of previously existing next level mapping. Since, we are going to overrite previous mapping, the only reference to next level page table will get lost and the next level page table will be zombie, occupying space forever. So, free it before overriding. Signed-off-by: Chintan Pandya --- arch/arm64/mm/mmu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 8c704f1..c0df264 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -32,7 +32,7 @@ #include #include #include - +#include #include #include #include @@ -45,6 +45,7 @@ #include #include #include +#include #define NO_BLOCK_MAPPINGS BIT(0) #define NO_CONT_MAPPINGS BIT(1) @@ -939,6 +940,9 @@ int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) return 0; BUG_ON(phys & ~PUD_MASK); + if (pud_val(*pud) && !pud_huge(*pud)) + free_page((unsigned long)__va(pud_val(*pud))); + set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot)); return 1; } @@ -953,6 +957,9 @@ int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) return 0; BUG_ON(phys & ~PMD_MASK); + if (pmd_val(*pmd) && !pmd_huge(*pmd)) + free_page((unsigned long)__va(pmd_val(*pmd))); + set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot)); return 1; }