Received: by 10.223.185.116 with SMTP id b49csp5322461wrg; Wed, 7 Mar 2018 09:48:57 -0800 (PST) X-Google-Smtp-Source: AG47ELtmkXq/X0jalAAcYk7eYTW8AEEAINdaff3SWBtGLhqaxKGJebHnRgdGEcl/Ywz/PKWy+1s0 X-Received: by 10.99.147.91 with SMTP id w27mr19110142pgm.208.1520444937087; Wed, 07 Mar 2018 09:48:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520444937; cv=none; d=google.com; s=arc-20160816; b=cNX1OK8Q4psSUEDlYuf65w/qh+sJAU1QNYZA2QpXbhdbDwLnR0BDhlkmnLLGUFB0HA eb9tYr9P4Tpu+NWiVwcGUgqLn4lxXsHbhK/wRAWEtlyoU8WTqyeKLiY1+cDM8psIL5rG Q1FJCKIlnHAFXeFgRankNOl0uUiGhkL1nrz0ZFQl6kZITfEKNm/McWeVCxdBMgrj+GD7 ctxVooKFX/c2Kj4q591n7tpK3rGbvujPqK6Jd4O7U/RevG21+IH3Wd8LiTHN0EfRSLxI ZQVJzDiZmShtI1EBJFAAgYb3x5cVBgz7OKl3oAmwKHnSfppRbr23LJr7BBfNBclkfjOS H2vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=MFslykIt3QZFwvroY7LKrQhPW9D3nnG+tCGhTUMP/Yg=; b=zX1EH/2o3v3sf2fOLe4WRpxuZ9k/BLpQBwc3JxQCRZ9PvBtLYlfF+bnTbK9StPSo0e eIglLftT/an5Zc1pHfgwOf0TXmihXiL/FeHwFMBFHBs3Hmer5fZrW/Zidhr3h2To+oFb mojiQa7o3hKaZTLRy1qZCTRMe0yYhX+3q2m317yICf5qRN5enSh8MvEju3G4XqUAkuyB xkObZ+EyEL+gsxx1Bf2eSf8577T0Fl7m8MRPGV2/NO/kUK1Pb3z1693MfLvxeksRDgnY /JzE7nm8PJHYuzETlx+Fx3BWrm+lNmvwzgx0Za3qjCKF4p1FYmUJEC1hGfbuI5LLc7Os TcOg== ARC-Authentication-Results: i=1; mx.google.com; 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 d90-v6si13316990pld.40.2018.03.07.09.48.42; Wed, 07 Mar 2018 09:48:57 -0800 (PST) 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; 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 S933596AbeCGRre (ORCPT + 99 others); Wed, 7 Mar 2018 12:47:34 -0500 Received: from g2t2354.austin.hpe.com ([15.233.44.27]:4317 "EHLO g2t2354.austin.hpe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751211AbeCGRrd (ORCPT ); Wed, 7 Mar 2018 12:47:33 -0500 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2354.austin.hpe.com (Postfix) with ESMTP id 2F252C5; Wed, 7 Mar 2018 17:47:33 +0000 (UTC) Received: from misato.americas.hpqcorp.net (misato.americas.hpqcorp.net [10.34.81.122]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 0099236; Wed, 7 Mar 2018 17:47:30 +0000 (UTC) From: Toshi Kani To: mhocko@suse.com, akpm@linux-foundation.org, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, bp@suse.de, catalin.marinas@arm.com Cc: guohanjun@huawei.com, will.deacon@arm.com, wxf.wang@hisilicon.com, linux-mm@kvack.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/2] fix memory leak / panic in ioremap huge pages Date: Wed, 7 Mar 2018 11:32:25 -0700 Message-Id: <20180307183227.17983-1-toshi.kani@hpe.com> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On architectures with CONFIG_HAVE_ARCH_HUGE_VMAP set, ioremap() may create pud/pmd mappings. Kernel panic was observed on arm64 systems with Cortex-A75 in the following steps as described by Hanjun Guo. [1] 1. ioremap a 4K size, valid page table will build, 2. iounmap it, pte0 will set to 0; 3. ioremap the same address with 2M size, pgd/pmd is unchanged, then set the a new value for pmd; 4. pte0 is leaked; 5. CPU may meet exception because the old pmd is still in TLB, which will lead to kernel panic. This panic is not reproducible on x86. INVLPG, called from iounmap, purges all levels of entries associated with purged address on x86. x86 still has memory leak. Patch 01 adds new interfaces as stubs, which work as workaround of this issue. This patch 01 was leveraged from Hanjun's patch. [1] Patch 02 fixes the issue on x86 by implementing the interfaces. [1] https://patchwork.kernel.org/patch/10134581/ --- Toshi Kani (2): 1/2 mm/vmalloc: Add interfaces to free unused page table 2/2 x86/mm: implement free pmd/pte page interfaces --- arch/arm64/mm/mmu.c | 10 ++++++++++ arch/x86/mm/pgtable.c | 44 +++++++++++++++++++++++++++++++++++++++++++ include/asm-generic/pgtable.h | 10 ++++++++++ lib/ioremap.c | 6 ++++-- 4 files changed, 68 insertions(+), 2 deletions(-)