Received: by 10.213.65.68 with SMTP id h4csp851170imn; Wed, 14 Mar 2018 01:51:28 -0700 (PDT) X-Google-Smtp-Source: AG47ELv6nQ7+6Kp72NjyLhz6cJV6ai/H+hBnfEeep22+R+ALYlCuk4GuP/OzfGkKlo+sKYwibCDx X-Received: by 2002:a17:902:538f:: with SMTP id c15-v6mr3332161pli.90.1521017488056; Wed, 14 Mar 2018 01:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521017488; cv=none; d=google.com; s=arc-20160816; b=ntu99PwMqk5GGL8SoiZLk3XhkJ652ZEtfynjXwExM0XwGZztFx87Z+k4ax2YeBriwS +s+hWaVWwpj83Qt9XJoTw8a5fyZGBdWQxIH5VqXnk95X0RuD0puovrqU7+nNeDVwOKjU rMRndyYuPK9TTgUfdpSC5ympG4Psn5wFXJzBr7hYwNx6TYOg7+EOv38CLSgB/pQY5lzh QAWm9O7vxy4wZoi5pORx9ueXMg98fbWR8QomkolNiKfBtGwPZfAMniEyhns2KVSyjUCr 5JthCQVr6in1cOevvrNOhEC5MDrzPi+f6NZUvfwIIe7iPg2qQ/a1LThWepmNl3w+vWA9 jLVg== 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=lrEyAjRlXQHBVl1/Ikbo7D3DIQ4hJFOVa7fn6/ZvHXc=; b=hWkUQAljmBuKFJ7r++7a+6WHwVOWm/HFu1YQ6uiZiTgGFasjMvS9OFkdGbd52yXB1l c4mPdnN90FCpyucn8r2y6jM7KPbN2LA5Erf8aDbKbHBzaOQknw0Dw2Y1n9XCQar030P4 UP37KmMq//UxmnyYd05q0g+v6kTMCGDktS+9//+TMxYhMXTOvIBM0sJAQOD5Di7w+CaF Zt6+A/EUHlakZIFFzRMiR9OUqcnu8oGFVKfOlaeeHG/ZRk8AqfAi1EPtID03yDyqBG/N /azstBhkGPQRPVvFwJqgdsthosOECOsfYTj7+/lSNujGnSdUf6DU63z8L2fRN5I1YLzX UNmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=b+288mJz; dkim=pass header.i=@codeaurora.org header.s=default header.b=YczjPr3l; 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 g6si1549154pgp.434.2018.03.14.01.51.13; Wed, 14 Mar 2018 01:51:28 -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=b+288mJz; dkim=pass header.i=@codeaurora.org header.s=default header.b=YczjPr3l; 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 S1753302AbeCNItv (ORCPT + 99 others); Wed, 14 Mar 2018 04:49:51 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58634 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753394AbeCNIsx (ORCPT ); Wed, 14 Mar 2018 04:48:53 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7C925608CB; 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=1521017332; bh=0cbaYAReSctfUKsE9ry3OLwsRwLHi76ohNnH7VdlyXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b+288mJzf3AksEepNAiC+59gdA93SWkqUsKkQ9TpPcoqAiIEtyIf0BcziDwB/ovT7 V4PEgmNStcB0mNsGxXfQIM5urFxB2xtAX4lZssvdvK/2VC46Sw7QXaZaFK26m+sxJR PUlcsuy5O8WcXCIffaSuE6ymX0n8al7CR2Ulx1eA= 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 877C3608CB; Wed, 14 Mar 2018 08:48:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521017331; bh=0cbaYAReSctfUKsE9ry3OLwsRwLHi76ohNnH7VdlyXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YczjPr3lQcLJmtqrTfjqq+nx4hRDOxkl9mhaTITykULOfH4lo14nTyaPFT6XxfyN+ XtN/ZbGRUF/i5OxEn2Ly7qrFJZ0hHtuS2NzN5n97RgZD7ZkXXHAz7pr2QRPWUsWM7n va1MpsLAcdZtlHQTsoGDJkppqf5QHHEXWTj3MSv8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 877C3608CB 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 v1 2/4] ioremap: Invalidate TLB after huge mappings Date: Wed, 14 Mar 2018 14:18:23 +0530 Message-Id: <1521017305-28518-3-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If huge mappings are enabled, they can override valid intermediate previous mappings. Some MMU can speculatively pre-fetch these intermediate entries even after unmap. That's because unmap will clear only last level entries in page table keeping intermediate (pud/pmd) entries still valid. This can potentially lead to stale TLB entries which needs invalidation after map. Some more info: https://lkml.org/lkml/2017/12/23/3 There is one noted case for ARM64 where such stale TLB entries causes 3rd level translation fault even after correct (huge) mapping is available. See the case below (reproduced locally with tests), [17505.330123] Unable to handle kernel paging request at virtual address ffffff801ae00000 [17505.338100] pgd = ffffff800a761000 [17505.341566] [ffffff801ae00000] *pgd=000000017e1be003, *pud=000000017e1be003, *pmd=00e8000098000f05 [17505.350704] ------------[ cut here ]------------ [17505.355362] Kernel BUG at ffffff8008238c30 [verbose debug info unavailable] [17505.362375] Internal error: Oops: 96000007 [#1] PREEMPT SMP [17505.367996] Modules linked in: [17505.371114] CPU: 6 PID: 488 Comm: chintan-ioremap Not tainted 4.9.81+ #160 [17505.378039] Hardware name: Qualcomm Technologies, Inc. SDM845 v1 MTP (DT) [17505.384885] task: ffffffc0e3e61180 task.stack: ffffffc0e3e70000 [17505.390868] PC is at io_remap_test+0x2e0/0x444 [17505.395352] LR is at io_remap_test+0x2d0/0x444 [17505.399835] pc : [] lr : [] pstate: 60c00005 [17505.407282] sp : ffffffc0e3e73d70 [17505.410624] x29: ffffffc0e3e73d70 x28: ffffff801ae00008 [17505.416031] x27: ffffff801ae00010 x26: ffffff801ae00018 [17505.421436] x25: ffffff801ae00020 x24: ffffff801adfffe0 [17505.426840] x23: ffffff801adfffe8 x22: ffffff801adffff0 [17505.432244] x21: ffffff801adffff8 x20: ffffff801ae00000 [17505.437648] x19: 0000000000000005 x18: 0000000000000000 [17505.443052] x17: 00000000b3409452 x16: 00000000923da470 [17505.448456] x15: 0000000071c9763c x14: 00000000a15658fa [17505.453860] x13: 000000005cae96bf x12: 00000000e6d5c44a [17505.459264] x11: 0140000000000000 x10: ffffff80099a1000 [17505.464668] x9 : 0000000000000000 x8 : ffffffc0e3e73d68 [17505.470072] x7 : ffffff80099d3220 x6 : 0000000000000015 [17505.475476] x5 : 00000c00004ad32a x4 : 000000000000000a [17505.480880] x3 : 000000000682aaab x2 : 0000001345c2ad2e [17505.486284] x1 : 7d78d61de56639ba x0 : 0000000000000001 Hence, invalidate once we override pmd/pud with huge mappings. Signed-off-by: Chintan Pandya --- lib/ioremap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ioremap.c b/lib/ioremap.c index b808a39..c1e1341 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; @@ -92,8 +93,10 @@ 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)) { - if (pmd_set_huge(pmd, phys_addr + addr, prot)) + if (pmd_set_huge(pmd, phys_addr + addr, prot)) { + flush_tlb_pgtable(&init_mm, addr); continue; + } } if (ioremap_pte_range(pmd, addr, next, phys_addr + addr, prot)) @@ -118,8 +121,10 @@ 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)) { - if (pud_set_huge(pud, phys_addr + addr, prot)) + if (pud_set_huge(pud, phys_addr + addr, prot)) { + flush_tlb_pgtable(&init_mm, addr); continue; + } } 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