Received: by 10.213.65.68 with SMTP id h4csp903457imn; Wed, 14 Mar 2018 03:49:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELtouVP6dUrGqZrGQYjpL9euA1mzT2McYGAnedNhWnpxlwWZYQReea+BvB8n2/9m3fHvSqzh X-Received: by 2002:a17:902:b7cb:: with SMTP id v11-v6mr3683489plz.206.1521024583600; Wed, 14 Mar 2018 03:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521024583; cv=none; d=google.com; s=arc-20160816; b=pgfZqJzr/Fpl10UsjsQDam3xzgLj+VrFalCZVtLoAIjayXaoMaHUSEma0GE2b26+hJ ns8OaXf+S4JvOkeS9A8L7GNL/sJoEvJNowaafAOFi+gQKENIlmDlKklmlmMLtDqKj++C r/4FQchF2asAq9KYmoUZi08psbCdVO9X5yh2KR4qxs6BctsePoTSzQBMcqliE7hn7R3y 5x6j94wkSHvJEVPv9VBRdmekzhci2GRabYu7ItGxdWyrgCAB1dJVnZh4axIXnzAbju5y 8/zDn2Nq1hZXbNW545j6Z8bp+CXdKQDB97ihg14JAezMmQLMSyspGRW3I+x6JURJrTHb kLOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=NjCY41x3Dj6qzg1oqlz3OG3/OVNalgSd1DxBGh31w9o=; b=I6I5f7p9+y2jON73SyuEyyoC6+St9H9d0RpCjI3r+jhcDNBDhWBagYogxGyCulFwfU QsnsOpoC2w5Dypgqmt6XdSyo+0y/ArXVODpQRxZNjq9LuxEa3H3G9dzFCrMiCCl9HDic uXAiNvheAJMj8iRuHLVZcgdeLhgmVnmDw8+WH0FY+I0Mo+IsM/NQNkNVr952UCYG1Inm YKgYuc+A6J4fPOCa2KkjrEQM4DEn5f2Z/5lDT7yjmwh+Hu+NnyG68wUYQGiXsRbNwbUs Jzrae2fXDELqYxim/7srXgidX5KHseOopP7zuscz2q6s7d5ZZrR3UoYr7ILUsgHFcThK 0wNw== 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 z7si1635897pgp.660.2018.03.14.03.49.29; Wed, 14 Mar 2018 03:49:43 -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; 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 S1751835AbeCNKsb (ORCPT + 99 others); Wed, 14 Mar 2018 06:48:31 -0400 Received: from foss.arm.com ([217.140.101.70]:50512 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751370AbeCNKs3 (ORCPT ); Wed, 14 Mar 2018 06:48:29 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B7E4B15AB; Wed, 14 Mar 2018 03:48:28 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 14A5B3F53D; Wed, 14 Mar 2018 03:48:25 -0700 (PDT) Date: Wed, 14 Mar 2018 10:48:23 +0000 From: Mark Rutland To: Chintan Pandya Cc: catalin.marinas@arm.com, will.deacon@arm.com, arnd@arndb.de, 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 Subject: Re: [PATCH v1 2/4] ioremap: Invalidate TLB after huge mappings Message-ID: <20180314104823.yumqomzmbu3cj442@lakrids.cambridge.arm.com> References: <1521017305-28518-1-git-send-email-cpandya@codeaurora.org> <1521017305-28518-3-git-send-email-cpandya@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1521017305-28518-3-git-send-email-cpandya@codeaurora.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 14, 2018 at 02:18:23PM +0530, Chintan Pandya wrote: > 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. > Hence, invalidate once we override pmd/pud with huge > mappings. > 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; > + } > } As has been noted in previous threads, the ARM architecture requires a Break-Before-Make sequence when changing an entry from a table to a block, as is the case here. The means the necessary sequence is: 1. Make the entry invalid 2. Invalidate relevant TLB entries 3. Write the new entry Whereas above, the sequence is 1. Write the new entry 2. invalidate relevant TLB entries Which is insufficient, and will lead to a number of problems. Therefore, NAK to this patch. Please read up on the Break-Before-Make requirements in the ARM ARM. Thanks, Mark.