Received: by 10.213.65.68 with SMTP id h4csp1641920imn; Thu, 15 Mar 2018 05:47:05 -0700 (PDT) X-Google-Smtp-Source: AG47ELupJZ3l5VKvxJoM7tRg/L7HM+tKiaS5/HMk5uGUiXGJeITZZ39s1IInPJpm7Snc1+PkX0vS X-Received: by 10.99.183.15 with SMTP id t15mr6822262pgf.416.1521118025014; Thu, 15 Mar 2018 05:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521118024; cv=none; d=google.com; s=arc-20160816; b=R+UlMsHuWJu5QtdCQcyzbDbGjpJhhviy+cdYhNq3yP85F/EfBGQK5axTFfsgxirgLh 4F5Zh7LGO+K7OZoY8FqSkFRZSGJ/aijK+ZCWnASlTEjvZNdLbG0a+iaCOC3ca3GdGgT/ G78facmmAbkRYts3ox1g1pxUrrfY8FuAESX93m4lk9ul28BF+CG/aq2AZrBdZ9aNwjYL Jq5F4CbUFMgw2MPP0kurCxORbIyxbQ6tYdOx1aYW7Ma6ME6s/1NoDoQ9n802mYkKe5ib ciVoDJVLii6/eUmN5eWmra7uIwc9XFN/6/ZV6riBv7oai89TsLvsrZW8l6IcIsUYld+O rS6A== 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=fw4doynvttiggochy+4egrEb0l8xGsaCoUlNpNLSyQ0=; b=tbaxJfx8s5egQLwnWpC94uy1anyFalMbcZvbjrxqBQMXKUObB05aVWjRu5Uo0gyUo+ S8d4ma4mU9eKuxc1fGKytiYONeulQOVXShkMib1xkVQiS4e3aDyRY9xoXcv3k+lqgs7+ A6691pdhybTp5fw2/Q09yN9yNfp0FNNc8jyhM/LApUMsz/c2vKLeM2R/Bw93D1jTeP0q 5JQ3IdxqxmV+84qEq0J22Y8Ip0mF419ywTcaPN0MV0c7d2pT3LphTYzY7J8KAJUEvi1w lk+lkOTXrWF51PEw+BTGB+G50LCxhpNw52vWOUIKTYSXBYYurUaMABrT49YJpJ9KtjGN Aw6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Cq/fzj12; dkim=pass header.i=@codeaurora.org header.s=default header.b=Veqb1xWO; 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 bc12-v6si3927340plb.336.2018.03.15.05.46.51; Thu, 15 Mar 2018 05:47:04 -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=Cq/fzj12; dkim=pass header.i=@codeaurora.org header.s=default header.b=Veqb1xWO; 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 S1751943AbeCOMpl (ORCPT + 99 others); Thu, 15 Mar 2018 08:45:41 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:54918 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751357AbeCOMpj (ORCPT ); Thu, 15 Mar 2018 08:45:39 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CB82960C67; Thu, 15 Mar 2018 12:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521117938; bh=TagVRzbajSY/87Zh6vDfByCZk1Wo0XrxjYcct1jZkD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cq/fzj12B4BfLr4PRkUUo9I7/FnyGTUNJBq4m6zZYVDnf3oxybD1pLRqWY9K4ui+2 SeT97VsxIyTTY1I7EFj1lxVh5wapUeNpVXtRiiolzX3J72Jm0bO0IQF+OxDNWCGSXF FqBR/Nt2dTxu4eme5woyDD+KAZPPtV9pTEqMNlgs= 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 E7B4B600C1; Thu, 15 Mar 2018 12:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521117937; bh=TagVRzbajSY/87Zh6vDfByCZk1Wo0XrxjYcct1jZkD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Veqb1xWO6I1UYUlI/AlnQ0aeeBnq7VtoW0fOHqyd7Y2PowVmafav1YHZ1CQWvMv/n r8P25SCnb/evVDjrM2eHWe/ntb1slY2OUxpgPNLF8ixqx0lur/WJ7YifAHcVBclWnt D9AKA79VC1as9i1xqYRTXlLfrn8IfdGlK4fOK110= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E7B4B600C1 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 Cc: mark.rutland@arm.com, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, james.morse@arm.com, kristina.martsenko@arm.com, takahiro.akashi@linaro.org, gregkh@linuxfoundation.org, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, akpm@linux-foundation.org, toshi.kani@hpe.com, Chintan Pandya Subject: [PATCH v2 2/4] ioremap: Implement TLB_INV before huge mapping Date: Thu, 15 Mar 2018 18:15:04 +0530 Message-Id: <1521117906-20107-3-git-send-email-cpandya@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1521117906-20107-1-git-send-email-cpandya@codeaurora.org> References: <1521117906-20107-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 Huge mapping changes PMD/PUD which could have valid previous entries. This requires proper TLB maintanance on some architectures, like ARM64. Implent BBM (break-before-make) safe TLB invalidation. Here, I've used flush_tlb_pgtable() instead of flush_kernel_range() because invalidating intermediate page_table entries could have been optimized for specific arch. That's the case with ARM64 at least. Signed-off-by: Chintan Pandya --- lib/ioremap.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/ioremap.c b/lib/ioremap.c index 54e5bba..55f8648 100644 --- a/lib/ioremap.c +++ b/lib/ioremap.c @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP static int __read_mostly ioremap_p4d_capable; @@ -80,6 +81,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { pmd_t *pmd; + pmd_t old_pmd; unsigned long next; phys_addr -= addr; @@ -91,10 +93,15 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr, if (ioremap_pmd_enabled() && ((next - addr) == PMD_SIZE) && - IS_ALIGNED(phys_addr + addr, PMD_SIZE) && - pmd_free_pte_page(pmd)) { - if (pmd_set_huge(pmd, phys_addr + addr, prot)) + IS_ALIGNED(phys_addr + addr, PMD_SIZE)) { + old_pmd = *pmd; + pmd_clear(pmd); + flush_tlb_pgtable(&init_mm, addr); + if (pmd_set_huge(pmd, phys_addr + addr, prot)) { + pmd_free_pte_page(&old_pmd); continue; + } else + set_pmd(pmd, old_pmd); } if (ioremap_pte_range(pmd, addr, next, phys_addr + addr, prot)) @@ -107,6 +114,7 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, phys_addr_t phys_addr, pgprot_t prot) { pud_t *pud; + pud_t old_pud; unsigned long next; phys_addr -= addr; @@ -118,10 +126,15 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr, if (ioremap_pud_enabled() && ((next - addr) == PUD_SIZE) && - IS_ALIGNED(phys_addr + addr, PUD_SIZE) && - pud_free_pmd_page(pud)) { - if (pud_set_huge(pud, phys_addr + addr, prot)) + IS_ALIGNED(phys_addr + addr, PUD_SIZE)) { + old_pud = *pud; + pud_clear(pud); + flush_tlb_pgtable(&init_mm, addr); + if (pud_set_huge(pud, phys_addr + addr, prot)) { + pud_free_pmd_page(&old_pud); continue; + } else + set_pud(pud, old_pud); } if (ioremap_pmd_range(pud, addr, next, phys_addr + addr, prot)) -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project