From patchwork Thu Aug 16 18:41:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 10567985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76A8B109C for ; Thu, 16 Aug 2018 18:43:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 744142B8B0 for ; Thu, 16 Aug 2018 18:43:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 720672B885; Thu, 16 Aug 2018 18:43:04 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C77EB2B8B0 for ; Thu, 16 Aug 2018 18:43:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 598616B030A; Thu, 16 Aug 2018 14:43:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 520306B030B; Thu, 16 Aug 2018 14:43:02 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C1B46B030C; Thu, 16 Aug 2018 14:43:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id E8EED6B030B for ; Thu, 16 Aug 2018 14:43:01 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id q21-v6so2467978pff.21 for ; Thu, 16 Aug 2018 11:43:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:user-agent :mime-version; bh=JDzs0tfz7YhIu0BEK7CjYJtoXeviGIslnROlb/dIWxk=; b=jDZcirqgoioJjywOJH8RU7+utiS2GNSMztPVHJ7qw0lBXiPywyaP7+ZWQKCPjvlnr0 rocJz8RLZEKRJZc/MPcNsCUxT9FFI34+xVWCVmwvSBk8d5rZlSr7q6RYhYHPZxGBl/gh jS5i/cC17goYMimYjDQZHg7CAdxDDYR8gNeJKj9EQ9txjR57hLnZRYus+wDEWxIPjW5E xDGaMKnKpih2dTFAQM2LiuG3xsYgOjBlwyMfqkESj8cdK7ZEXFALgqH6pjmTbFF46z1q hy4QRwY1rEkMwDXKpg6VQH+6vZXnF4ZUKvmqxrVaBFkv6Q5VOthEzfE7kcK5ZCh2yjXk /tNA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org X-Gm-Message-State: AOUpUlG0YWz9JwpksqX4qZqZSHvmE+I9HEg1RW9lVR7uRUQswOO3iZC7 WVUc5Fi3MRawvfvRMxVTK+/b6+popjG5Ap/3Te2UDBE10uz/IKvbYLrrYShu0e+HOW70BX81xuA Es/MBaMC0jH42ji244DK8OMBT/Ufymq8DbGzAA4b1N4iz+gfn1EE7aOSp9hUQ1HEDIg== X-Received: by 2002:a63:6849:: with SMTP id d70-v6mr29257680pgc.7.1534444981624; Thu, 16 Aug 2018 11:43:01 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxxoeOnBc0vrX9yWgjkEYjiDSg2oEgaeMagQ/p78AGf9ktbocC/9H+tnwXwzQ0ToynivwPJ X-Received: by 2002:a63:6849:: with SMTP id d70-v6mr29257651pgc.7.1534444980886; Thu, 16 Aug 2018 11:43:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534444980; cv=none; d=google.com; s=arc-20160816; b=UKdvsfzajh+3fBYEpEheY7Lq2e8Rcdz7/w9dhBKKu+Tlei0MtmHYZX9f/uzhyYmGOm t8ICxPFyEHJWruMYCFbjAD+mE29tgwBhm/MMKSLQ63EtCm3x0pwOPybR/fyObqm+n7MQ W7F5DvcFgi0BVmc2hWIXtM2mhfO2Dss+BZbtlbpN13O37cL2kssH08l4WQ1gPY7fKDU4 KeFqHf67wKxQWfD1D8I02wG0kiOazCd+FOCq4buSl/idQYxA2EJdCLF29uKBmta7Jzbo 9BMi4zrcZa2owtBHB/4aYd3ovl8IL1fWkoy+jzmdKiHPa9OlgaQDd3DIu9i0ai12I94q JU0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=JDzs0tfz7YhIu0BEK7CjYJtoXeviGIslnROlb/dIWxk=; b=ngjtjaZmjrFunN8IYLwb4Itu5RQxkq9PomSLw8/8rWkfoNMWXGDQkiOrmHcBsK2HfX IA/rSKR2Z8DeQ0wMq7Et7pQalv+VarqV//Yz1kXY54u5NrIi+wrfJLgqYUAadQNNhqiU e12TL1f2X/6RVLOGcKQ34NA8DNMCEVtmUlf7BKwTZHHvYuffa8n2FnIMvjPNNcdYCloq kKFtuDdjmHn+4uBAagbqfBfCBmjpFavLCK0IMZDTOLfcg95tdMQaBdCHVZZ+rhfmVoj9 nvPjSiKHI+adlGrSU5JGF8vwa0cvbNFsURMuKznvrCeeErpiebaDHjkpNeVPr5vxeh+3 vFvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id cb1-v6si54059plb.128.2018.08.16.11.43.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 11:43:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) client-ip=140.211.169.12; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 010A3CC4; Thu, 16 Aug 2018 18:43:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joerg Roedel , Toshi Kani , Thomas Gleixner , mhocko@suse.com, akpm@linux-foundation.org, hpa@zytor.com, cpandya@codeaurora.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 4.4 01/13] x86/mm: Disable ioremap free page handling on x86-PAE Date: Thu, 16 Aug 2018 20:41:48 +0200 Message-Id: <20180816171628.612166526@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816171628.554317013@linuxfoundation.org> References: <20180816171628.554317013@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Toshi Kani commit f967db0b9ed44ec3057a28f3b28efc51df51b835 upstream. ioremap() supports pmd mappings on x86-PAE. However, kernel's pmd tables are not shared among processes on x86-PAE. Therefore, any update to sync'd pmd entries need re-syncing. Freeing a pte page also leads to a vmalloc fault and hits the BUG_ON in vmalloc_sync_one(). Disable free page handling on x86-PAE. pud_free_pmd_page() and pmd_free_pte_page() simply return 0 if a given pud/pmd entry is present. This assures that ioremap() does not update sync'd pmd entries at the cost of falling back to pte mappings. Fixes: 28ee90fe6048 ("x86/mm: implement free pmd/pte page interfaces") Reported-by: Joerg Roedel Signed-off-by: Toshi Kani Signed-off-by: Thomas Gleixner Cc: mhocko@suse.com Cc: akpm@linux-foundation.org Cc: hpa@zytor.com Cc: cpandya@codeaurora.org Cc: linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org Cc: stable@vger.kernel.org Cc: Andrew Morton Cc: Michal Hocko Cc: "H. Peter Anvin" Cc: Link: https://lkml.kernel.org/r/20180627141348.21777-2-toshi.kani@hpe.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pgtable.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -676,6 +676,7 @@ int pmd_clear_huge(pmd_t *pmd) return 0; } +#ifdef CONFIG_X86_64 /** * pud_free_pmd_page - Clear pud entry and free pmd page. * @pud: Pointer to a PUD. @@ -723,4 +724,22 @@ int pmd_free_pte_page(pmd_t *pmd) return 1; } + +#else /* !CONFIG_X86_64 */ + +int pud_free_pmd_page(pud_t *pud) +{ + return pud_none(*pud); +} + +/* + * Disable free page handling on x86-PAE. This assures that ioremap() + * does not update sync'd pmd entries. See vmalloc_sync_one(). + */ +int pmd_free_pte_page(pmd_t *pmd) +{ + return pmd_none(*pmd); +} + +#endif /* CONFIG_X86_64 */ #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */ From patchwork Thu Aug 16 18:41:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 10567989 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FFCC15E2 for ; Thu, 16 Aug 2018 18:43:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3C86285A5 for ; Thu, 16 Aug 2018 18:43:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97E25288C4; Thu, 16 Aug 2018 18:43:21 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D32A2285A5 for ; Thu, 16 Aug 2018 18:43:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9A136B030E; Thu, 16 Aug 2018 14:43:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E21A36B030F; Thu, 16 Aug 2018 14:43:19 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEA856B0310; Thu, 16 Aug 2018 14:43:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 87E2B6B030E for ; Thu, 16 Aug 2018 14:43:19 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id t4-v6so3275994plo.0 for ; Thu, 16 Aug 2018 11:43:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:user-agent :mime-version; bh=51yKbDQaxspeYjvzQgk5RIMAi6QK88zzw+vQ6SfN+ls=; b=a7DJts2s8NWnfkAk0Q6e15yXjj+kxa64w64RTtI4tXoNvfyeXLt/46Yk+Q76WBra/d uOPAbLCi3fWKN7H6cC0VQYfUW76kdrREkeuUdcSjFPN0S4LvbwaWGt6tEaHE1d3fxKy/ UwyIjMgpBueChhvYEXxWV+u4I6zmyAcmbiBho9SIxPrkeVvtmBMbCcuZpdjJi/+qnIdG qly2bVm6EK5KOCLzwJaqWE+GDuVF1SIiHojvraSOQa+vosBSYHvceHIl2/eBbrawWA8v QZFe+a/ZE+yaSquuzT5TX20KEo85++RlI5CDX5x/NzxT/lue/Ip6ZTQ0aqce8o29XkFO wOsw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org X-Gm-Message-State: AOUpUlFRd4z/goSJd/qIUzhgmIzXCjctL58OI2Q5/Ojei5eEF9FlCB/D 0MX10Mp1cZSXaV5JG92bSBUIdnKFe4QcwJPsvAKYzx0+pMJ757SR0uPg9+wEQVZxFyx37Ctr6dZ 3MchVsZDWx/cnUzkrQ/lWyC8mwr0rGe01p6avGnUg8T9bBE/aGaV7lbf7UuiKDSn/BA== X-Received: by 2002:a63:7412:: with SMTP id p18-v6mr24890384pgc.395.1534444999216; Thu, 16 Aug 2018 11:43:19 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzoiwRPvbbmVSQvlvn4YPESnJfE2upBHPrhZWcc3JawVufDWlLGwE6TVWjpsQK2FZOmqVm2 X-Received: by 2002:a63:7412:: with SMTP id p18-v6mr24890355pgc.395.1534444998468; Thu, 16 Aug 2018 11:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534444998; cv=none; d=google.com; s=arc-20160816; b=oHgmjTJt8BaWX3EKeXAzFjMpT35JE0ijQM6W8RrwOQrcvsRYnpP2/Mn2TUcN4o+S9H UUSVIzmv/S9zJ3TUqKVmPOaKN41ZSs5MiQERiRZDPTVUg3Nl1rbhHbA9+89ewedU2aDe d/Sx/4p6SSEIJ1TUvqcTGuLvE18XiT5Aklw/e0PNLudK291ZCDh6sC/hOJubzh9HeQlC HUqrVJ/W+falJdQbiGZ3t6EfSGLdAc5ijiT7TYqeiEAuibz0jbTXQsqEeC7q35Wqxejp V93p6b1j+5v2rycZz5f5b/LBGdBWmBADOCM1yxSeimIEMcMs1UP00PEnhir5cySN3J1S c//A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=51yKbDQaxspeYjvzQgk5RIMAi6QK88zzw+vQ6SfN+ls=; b=HtmAHGGHQaYEzV2kUinoWK8z7XRmqg1aGa5oXq4AQWMZbeJWUeVNgQKa/7Z+mRAQNr 2DqdItQe/x/Uo7jjiuNEiQ5nhOvRYa0nbyI/nAe/3Jn5IEAx9X+volmnKhsYJLtvITFD FimLrqQen1ImIijyA5cO1viGu4zfoWHC2zv5zl5WTMXB4vxy4ocLjyAyeeun3HsHbtnE grRv1YYMwe1dHXpFhXkeXC159L46MtN0lMHLpiTNDZK4s/0j6cfzyQifgOVZ//0D65hI f1YyHsTOHXzkKcqx83/s/ouW5geKUWZEI3M1u14GXYwIw6f39m8tpkce2CUOiDNbP10v XIEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id i28-v6si50752pfi.105.2018.08.16.11.43.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 11:43:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) client-ip=140.211.169.12; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A6329CB7; Thu, 16 Aug 2018 18:43:16 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chintan Pandya , Toshi Kani , Thomas Gleixner , mhocko@suse.com, akpm@linux-foundation.org, hpa@zytor.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Will Deacon , Joerg Roedel Subject: [PATCH 4.4 12/13] ioremap: Update pgtable free interfaces with addr Date: Thu, 16 Aug 2018 20:41:59 +0200 Message-Id: <20180816171629.160523719@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816171628.554317013@linuxfoundation.org> References: <20180816171628.554317013@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chintan Pandya commit 785a19f9d1dd8a4ab2d0633be4656653bd3de1fc upstream. The following kernel panic was observed on ARM64 platform due to a stale TLB entry. 1. ioremap with 4K size, a valid pte page table is set. 2. iounmap it, its pte entry is set to 0. 3. ioremap the same address with 2M size, update its pmd entry with a new value. 4. CPU may hit an exception because the old pmd entry is still in TLB, which leads to a kernel panic. Commit b6bdb7517c3d ("mm/vmalloc: add interfaces to free unmapped page table") has addressed this panic by falling to pte mappings in the above case on ARM64. To support pmd mappings in all cases, TLB purge needs to be performed in this case on ARM64. Add a new arg, 'addr', to pud_free_pmd_page() and pmd_free_pte_page() so that TLB purge can be added later in seprate patches. [toshi.kani@hpe.com: merge changes, rewrite patch description] Fixes: 28ee90fe6048 ("x86/mm: implement free pmd/pte page interfaces") Signed-off-by: Chintan Pandya Signed-off-by: Toshi Kani Signed-off-by: Thomas Gleixner Cc: mhocko@suse.com Cc: akpm@linux-foundation.org Cc: hpa@zytor.com Cc: linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org Cc: Will Deacon Cc: Joerg Roedel Cc: stable@vger.kernel.org Cc: Andrew Morton Cc: Michal Hocko Cc: "H. Peter Anvin" Cc: Link: https://lkml.kernel.org/r/20180627141348.21777-3-toshi.kani@hpe.com Signed-off-by: Greg Kroah-Hartman --- arch/arm64/mm/mmu.c | 4 ++-- arch/x86/mm/pgtable.c | 12 +++++++----- include/asm-generic/pgtable.h | 8 ++++---- lib/ioremap.c | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -699,12 +699,12 @@ void *__init fixmap_remap_fdt(phys_addr_ } #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP -int pud_free_pmd_page(pud_t *pud) +int pud_free_pmd_page(pud_t *pud, unsigned long addr) { return pud_none(*pud); } -int pmd_free_pte_page(pmd_t *pmd) +int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) { return pmd_none(*pmd); } --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -680,11 +680,12 @@ int pmd_clear_huge(pmd_t *pmd) /** * pud_free_pmd_page - Clear pud entry and free pmd page. * @pud: Pointer to a PUD. + * @addr: Virtual address associated with pud. * * Context: The pud range has been unmaped and TLB purged. * Return: 1 if clearing the entry succeeded. 0 otherwise. */ -int pud_free_pmd_page(pud_t *pud) +int pud_free_pmd_page(pud_t *pud, unsigned long addr) { pmd_t *pmd; int i; @@ -695,7 +696,7 @@ int pud_free_pmd_page(pud_t *pud) pmd = (pmd_t *)pud_page_vaddr(*pud); for (i = 0; i < PTRS_PER_PMD; i++) - if (!pmd_free_pte_page(&pmd[i])) + if (!pmd_free_pte_page(&pmd[i], addr + (i * PMD_SIZE))) return 0; pud_clear(pud); @@ -707,11 +708,12 @@ int pud_free_pmd_page(pud_t *pud) /** * pmd_free_pte_page - Clear pmd entry and free pte page. * @pmd: Pointer to a PMD. + * @addr: Virtual address associated with pmd. * * Context: The pmd range has been unmaped and TLB purged. * Return: 1 if clearing the entry succeeded. 0 otherwise. */ -int pmd_free_pte_page(pmd_t *pmd) +int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) { pte_t *pte; @@ -727,7 +729,7 @@ int pmd_free_pte_page(pmd_t *pmd) #else /* !CONFIG_X86_64 */ -int pud_free_pmd_page(pud_t *pud) +int pud_free_pmd_page(pud_t *pud, unsigned long addr) { return pud_none(*pud); } @@ -736,7 +738,7 @@ int pud_free_pmd_page(pud_t *pud) * Disable free page handling on x86-PAE. This assures that ioremap() * does not update sync'd pmd entries. See vmalloc_sync_one(). */ -int pmd_free_pte_page(pmd_t *pmd) +int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) { return pmd_none(*pmd); } --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -770,8 +770,8 @@ int pud_set_huge(pud_t *pud, phys_addr_t int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); int pud_clear_huge(pud_t *pud); int pmd_clear_huge(pmd_t *pmd); -int pud_free_pmd_page(pud_t *pud); -int pmd_free_pte_page(pmd_t *pmd); +int pud_free_pmd_page(pud_t *pud, unsigned long addr); +int pmd_free_pte_page(pmd_t *pmd, unsigned long addr); #else /* !CONFIG_HAVE_ARCH_HUGE_VMAP */ static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) { @@ -789,11 +789,11 @@ static inline int pmd_clear_huge(pmd_t * { return 0; } -static inline int pud_free_pmd_page(pud_t *pud) +static inline int pud_free_pmd_page(pud_t *pud, unsigned long addr) { return 0; } -static inline int pmd_free_pte_page(pmd_t *pmd) +static inline int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) { return 0; } --- a/lib/ioremap.c +++ b/lib/ioremap.c @@ -84,7 +84,7 @@ static inline int ioremap_pmd_range(pud_ if (ioremap_pmd_enabled() && ((next - addr) == PMD_SIZE) && IS_ALIGNED(phys_addr + addr, PMD_SIZE) && - pmd_free_pte_page(pmd)) { + pmd_free_pte_page(pmd, addr)) { if (pmd_set_huge(pmd, phys_addr + addr, prot)) continue; } @@ -111,7 +111,7 @@ static inline int ioremap_pud_range(pgd_ if (ioremap_pud_enabled() && ((next - addr) == PUD_SIZE) && IS_ALIGNED(phys_addr + addr, PUD_SIZE) && - pud_free_pmd_page(pud)) { + pud_free_pmd_page(pud, addr)) { if (pud_set_huge(pud, phys_addr + addr, prot)) continue; } From patchwork Thu Aug 16 18:42:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 10567991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 937E5109C for ; Thu, 16 Aug 2018 18:43:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 976F7285A5 for ; Thu, 16 Aug 2018 18:43:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B05E288C4; Thu, 16 Aug 2018 18:43:27 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EECE9285A5 for ; Thu, 16 Aug 2018 18:43:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E71366B0310; Thu, 16 Aug 2018 14:43:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DFADD6B0311; Thu, 16 Aug 2018 14:43:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC2EE6B0312; Thu, 16 Aug 2018 14:43:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 833056B0310 for ; Thu, 16 Aug 2018 14:43:25 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id g36-v6so3282720plb.5 for ; Thu, 16 Aug 2018 11:43:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:user-agent :mime-version; bh=1mvKC+pQgaedM+C+0wh97GGHbL5QWexRPyd8NJTAFh0=; b=XcIWVMOyxcemlz5jtnLpnN/REGcxSsRR2uW9hSSWS7amEPdIJyBfCZAaJ/SgqaEren hFiduF2c0Z+kd2fA9k6LZIF2fie67BQYgU7sMDHBvvnARgkzolT9oF/y768pGmDoaG4W YGmDU8bWZkCAIkzHTNlQXpv0Be/ndYExjAmAzel+cMBDGrd7jgDDKM/uQA/xnLmHILz2 jx68pBpzFFtjRIAGBwwHPOm8xKwAnvEM8JV+wAq+tfC+poN4PChDWHBBcwtF0yJvJsOM IGcgdNz9R+GaKF1p4XQnpWumb9HcPyF9ddrENHWYdyi8XKkI879dn+3OjWE5PGvBNFxi k7SA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org X-Gm-Message-State: AOUpUlEhwLe8TGAOHibFTYF+1NDhqyRHoFoMAw3aHNi5Q8X8k0wQIPhk MVn6AhWrvI3qR9JYLEj0Iv6QMad1McWQWD8yko20Ge3JiMe7CYfXqRnEPdLlipP27LoPu2PIPYg qQwBS8QHs0qdZovNhEHQEQHIEgoJQN/KpmVanMeQQA2a+cx5FEZrqpvPaqX0U23livw== X-Received: by 2002:a62:8913:: with SMTP id v19-v6mr33711378pfd.127.1534445005223; Thu, 16 Aug 2018 11:43:25 -0700 (PDT) X-Google-Smtp-Source: AA+uWPznu4OmRlv3DVwp4BO5UvlCeBbOBSHkyBD8Wk6rTbR3n8I7uBTEOJoTbDx18w9q5rOZi2K6 X-Received: by 2002:a62:8913:: with SMTP id v19-v6mr33711351pfd.127.1534445004477; Thu, 16 Aug 2018 11:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534445004; cv=none; d=google.com; s=arc-20160816; b=fLX7Wg6+01IZcShP418TOdfXa08SwU6i7VD+OvaHqkvz+i3yDX7iQ0ICWN/CffU4zE XkIfkNjNnqFExs+bJNZHKwTqq3+bbtPuMuthjmBdDYZKK1mCxSm1pVEU4WPF00XOTFhn jti11EmIp2nse2W6XxB6jzKTK2dfrZsxt1yKlyMIWSpdbUfd7pNfybb2W7XMOgT+hzmc io74pfY/s7JxKlzjUGixdQhowdqI0atn+dGbqbyBphdfeBx40kiqsplq/I12cbJeh5lJ Qdt51WL72hGSD3qxSQfih1qkA6/kMbZ+7jfiIdxpP1U2guTNBLNJBkxj+7SXry90q7zK BlZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=1mvKC+pQgaedM+C+0wh97GGHbL5QWexRPyd8NJTAFh0=; b=0jl/1seZvFyo2eYkZv57TPsUG3pOOi24HawT12LFvbm1zWptyYjt/PCY4cXfLfRmHv KQ9fwCSY24jPx3Lr3KzzumjokurCxMCunLf1NAiE4RyggPdDlwadBp7s0BqdG0/Cab53 X8uZrGQLNO3x6QC3K/yVYK6j7PzyrALC8PNBBukvmkGM+lh2qY8Rpbh4bq+VByLhgPUR RT/0lQVbh+cCb+pXiFza//AyRVHZhWeihSz5GV3IgE4pPt2FlzRc+T33r8NGIWU6RB88 tg8/rQSIeWedRJd81CNeVGK0BQfcm9BIZgiLh81ANK/WKE+dPthq/ktgfetnKvQdURjI YqWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id u20-v6si37418pgj.443.2018.08.16.11.43.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 11:43:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) client-ip=140.211.169.12; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gregkh@linuxfoundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EAC81CC4; Thu, 16 Aug 2018 18:43:22 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Toshi Kani , Thomas Gleixner , mhocko@suse.com, akpm@linux-foundation.org, hpa@zytor.com, cpandya@codeaurora.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Joerg Roedel Subject: [PATCH 4.4 13/13] x86/mm: Add TLB purge to free pmd/pte page interfaces Date: Thu, 16 Aug 2018 20:42:00 +0200 Message-Id: <20180816171629.211063632@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816171628.554317013@linuxfoundation.org> References: <20180816171628.554317013@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Toshi Kani commit 5e0fb5df2ee871b841f96f9cb6a7f2784e96aa4e upstream. ioremap() calls pud_free_pmd_page() / pmd_free_pte_page() when it creates a pud / pmd map. The following preconditions are met at their entry. - All pte entries for a target pud/pmd address range have been cleared. - System-wide TLB purges have been peformed for a target pud/pmd address range. The preconditions assure that there is no stale TLB entry for the range. Speculation may not cache TLB entries since it requires all levels of page entries, including ptes, to have P & A-bits set for an associated address. However, speculation may cache pud/pmd entries (paging-structure caches) when they have P-bit set. Add a system-wide TLB purge (INVLPG) to a single page after clearing pud/pmd entry's P-bit. SDM 4.10.4.1, Operation that Invalidate TLBs and Paging-Structure Caches, states that: INVLPG invalidates all paging-structure caches associated with the current PCID regardless of the liner addresses to which they correspond. Fixes: 28ee90fe6048 ("x86/mm: implement free pmd/pte page interfaces") Signed-off-by: Toshi Kani Signed-off-by: Thomas Gleixner Cc: mhocko@suse.com Cc: akpm@linux-foundation.org Cc: hpa@zytor.com Cc: cpandya@codeaurora.org Cc: linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org Cc: Joerg Roedel Cc: stable@vger.kernel.org Cc: Andrew Morton Cc: Michal Hocko Cc: "H. Peter Anvin" Cc: Link: https://lkml.kernel.org/r/20180627141348.21777-4-toshi.kani@hpe.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pgtable.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -682,24 +682,44 @@ int pmd_clear_huge(pmd_t *pmd) * @pud: Pointer to a PUD. * @addr: Virtual address associated with pud. * - * Context: The pud range has been unmaped and TLB purged. + * Context: The pud range has been unmapped and TLB purged. * Return: 1 if clearing the entry succeeded. 0 otherwise. + * + * NOTE: Callers must allow a single page allocation. */ int pud_free_pmd_page(pud_t *pud, unsigned long addr) { - pmd_t *pmd; + pmd_t *pmd, *pmd_sv; + pte_t *pte; int i; if (pud_none(*pud)) return 1; pmd = (pmd_t *)pud_page_vaddr(*pud); - - for (i = 0; i < PTRS_PER_PMD; i++) - if (!pmd_free_pte_page(&pmd[i], addr + (i * PMD_SIZE))) - return 0; + pmd_sv = (pmd_t *)__get_free_page(GFP_KERNEL); + if (!pmd_sv) + return 0; + + for (i = 0; i < PTRS_PER_PMD; i++) { + pmd_sv[i] = pmd[i]; + if (!pmd_none(pmd[i])) + pmd_clear(&pmd[i]); + } pud_clear(pud); + + /* INVLPG to clear all paging-structure caches */ + flush_tlb_kernel_range(addr, addr + PAGE_SIZE-1); + + for (i = 0; i < PTRS_PER_PMD; i++) { + if (!pmd_none(pmd_sv[i])) { + pte = (pte_t *)pmd_page_vaddr(pmd_sv[i]); + free_page((unsigned long)pte); + } + } + + free_page((unsigned long)pmd_sv); free_page((unsigned long)pmd); return 1; @@ -710,7 +730,7 @@ int pud_free_pmd_page(pud_t *pud, unsign * @pmd: Pointer to a PMD. * @addr: Virtual address associated with pmd. * - * Context: The pmd range has been unmaped and TLB purged. + * Context: The pmd range has been unmapped and TLB purged. * Return: 1 if clearing the entry succeeded. 0 otherwise. */ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) @@ -722,6 +742,10 @@ int pmd_free_pte_page(pmd_t *pmd, unsign pte = (pte_t *)pmd_page_vaddr(*pmd); pmd_clear(pmd); + + /* INVLPG to clear all paging-structure caches */ + flush_tlb_kernel_range(addr, addr + PAGE_SIZE-1); + free_page((unsigned long)pte); return 1;