Received: by 10.213.65.68 with SMTP id h4csp921095imn; Wed, 14 Mar 2018 04:23:19 -0700 (PDT) X-Google-Smtp-Source: AG47ELtsJX9Ekr7VC+r55EORgglQVR2H0b1XfxYYrn+QvVThCM5nLnR//ouTrd08i18DnunTvglt X-Received: by 10.98.157.2 with SMTP id i2mr980366pfd.44.1521026599416; Wed, 14 Mar 2018 04:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521026599; cv=none; d=google.com; s=arc-20160816; b=0i4hfk82o4TV+Sw6K7jvBzDXeHXFA2pczJqmktCAi1UrMqmgQA9SbwItO+J6ywAGyB wAkpvwEBg5fZ3cmtPgKzPn9CRqbVmTR1G7Tz9Dy3lh2+CT8MBLhbblg8uny59ybAyzIH KPS4Hp4y6eaAmh8QtCrZ1upKzljBvZDXCL0i+MGDyM9O357GqMK5aZIL4Tfm94lVpNqL paoDtbTFThwL93APqrFeD1z1YowOQi+4xiP0C59X5fA92toCK8QIiy6QMWwa22t7JUx9 jpngYtd9hAY/t35ZkCyF4VxwwG1qGa04nMbR/bYyF7y/Ygi+Kd74qRVEssH0Hi+L8H5P Mhow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=kqb/T0iGCDxifSIh4ibKuBmndHWNpkrwhpe5yjwH19w=; b=rBu9HTFaDkzEu2eTuUqtjQhlvVE8nogiMXL/4kOP3WBu85hEG2lrQK8oo6YNY9QuK6 Qk3jHFJHYXQtK2N+gQfGz4w5h5ZsqLDTJJxTBdW+rm/5eX34rAAYNBiD6VeX3ICQNL2b rOWYy9Qahqkrh1b7zJpfraoVa06PqVrX99fJxYaZ1A8FR4E4lhTUb9+1Q9L7c3nFBzt1 /07i84Q6JuWkgC6vKnECbIfoZLWtUkzxy1beU5LhfVBaBRilUQ9I8eYi0g8BBTAUnjfJ WXFrNcQb/uQHQ6EqniSb1xRSs+cGJ9OMuojHG63zZMz5Kb9z8IQMhRXw1ieZZTnovlx6 Yqmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=G9l4/CBd; dkim=pass header.i=@codeaurora.org header.s=default header.b=hKYAL/bw; 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 a13si1669264pgt.344.2018.03.14.04.22.54; Wed, 14 Mar 2018 04:23:19 -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=G9l4/CBd; dkim=pass header.i=@codeaurora.org header.s=default header.b=hKYAL/bw; 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 S1751459AbeCNLUp (ORCPT + 99 others); Wed, 14 Mar 2018 07:20:45 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56072 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751015AbeCNLUn (ORCPT ); Wed, 14 Mar 2018 07:20:43 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 9C3FF6083C; Wed, 14 Mar 2018 11:20:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521026442; bh=dW3CubKX5TR3QPOE9xCf0c/QG7VSHFJYgTC8LgQdov4=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=G9l4/CBd3Xq+16icGLFORNEmxHq1TiP1FCy4Chwj+8KWuUpocYjq7caVj60zDxynM +ib3qSRINGvrXXOMUvuj7k+bP0TXIeXJfZc+omuV/MyQrVcjbNULyDSN7bF5iEqsX2 x/wwVuD7KAnRoP/oOiOIZGYZXpmg9UFwt9V+sZOQ= 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 [10.204.79.109] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cpandya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4D48860452; Wed, 14 Mar 2018 11:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1521026441; bh=dW3CubKX5TR3QPOE9xCf0c/QG7VSHFJYgTC8LgQdov4=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=hKYAL/bwFPq+IVkIgmqJObiw+isEGSq9Qv06XApJ416pdCatYn80Y0bFC9yITgeAi gNpTBxiORup69YvN2VKuf0bzyF66250Ri8Cl6I6jtgD8ChtL5QjZ2g/c+s2n+vHebC Ue6hmWluSPuwIpKwMxYAyb7xbky7jMR5mJT/Mr1Y= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4D48860452 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 Subject: Re: [PATCH v1 2/4] ioremap: Invalidate TLB after huge mappings To: Mark Rutland 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 References: <1521017305-28518-1-git-send-email-cpandya@codeaurora.org> <1521017305-28518-3-git-send-email-cpandya@codeaurora.org> <20180314104823.yumqomzmbu3cj442@lakrids.cambridge.arm.com> From: Chintan Pandya Message-ID: Date: Wed, 14 Mar 2018 16:50:35 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180314104823.yumqomzmbu3cj442@lakrids.cambridge.arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/14/2018 4:18 PM, Mark Rutland wrote: > 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 > We do this for PTEs. I don't see this applicable to PMDs. Because, 1) To mark any PMD invalid, we need to be sure that next level page table (I mean all the 512 PTEs) should be zero. That requires us to scan entire last level page. A big perf hit ! 2) We need to perform step 1 for every unmap as we never know which unmap will make last level page table empty. Moreover, problem comes only when 4K mapping was followed by 2M mapping. In all other cases, retaining valid PMD has obvious perf gain. That's what walk-cache is supposed to be introduced for. So, I think to touch only problematic case and fix it with TLB invalidate. > 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. I couldn't think of new problems with this approach. Could you share any problematic scenarios ? Also, my test-case runs fine with these patches for 10+ hours. > > Therefore, NAK to this patch. > > Please read up on the Break-Before-Make requirements in the ARM ARM. Sure, will get more from here. > > Thanks, > Mark. > Thanks for the review Mark. Chintan -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project