From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 883A0ECAAD3 for ; Fri, 9 Sep 2022 10:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4CCE8D0003; Fri, 9 Sep 2022 06:10:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FC5B8D0002; Fri, 9 Sep 2022 06:10:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89D078D0003; Fri, 9 Sep 2022 06:10:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 76D048D0002 for ; Fri, 9 Sep 2022 06:10:43 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 38ACDAB3D3 for ; Fri, 9 Sep 2022 10:10:43 +0000 (UTC) X-FDA: 79892127966.11.C1F95F2 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf27.hostedemail.com (Postfix) with ESMTP id B9864400D4 for ; Fri, 9 Sep 2022 10:10:42 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D25EAB82485; Fri, 9 Sep 2022 10:10:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFBBAC433C1; Fri, 9 Sep 2022 10:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662718239; bh=ThKc/LNks2uiEwibtZIMonrODWHgA8V6ISnUWceg9VI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JmgQnTSyduTWZtYc6DODkU0So3JcJ218EbkSzoY/dgU3Zm56uGjgw02ef25ftWUbW ft/mVHJRUfvEr8L3IpZK28TBYphWGB2loiVTm9EOSQ1REIu+kTHPiyGH1ttTMNKv1O OH8lklSHvtWxgwDalvI/0oszE8XSNNjneTsZOcXo55Rq97+gmAP5+GHre3WS5yXxiT x4h0JsVjQjfZaKbh3T0wVdny69SN2QiTP1wN+qpBJboyanMv2V/pAc5cQ9woB70o6b VYhQqS03VVlenck24B+QAUKBx1lum28864MwmcZYhxN8hrnSihqQLTF0YnXXBLRv5o hgh08i87IptXg== Date: Fri, 9 Sep 2022 11:10:34 +0100 From: Will Deacon To: "Kirill A. Shutemov" Cc: Sergei Antonov , linux-mm@kvack.org, akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, "Kirill A . Shutemov" Subject: Re: [PATCH] mm: bring back update_mmu_cache() to finish_fault() Message-ID: <20220909101032.GA32507@willie-the-truck> References: <20220908204809.2012451-1-saproj@gmail.com> <20220908222410.yg2sqqdezzwfi5mj@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220908222410.yg2sqqdezzwfi5mj@box.shutemov.name> User-Agent: Mutt/1.10.1 (2018-07-13) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662718242; a=rsa-sha256; cv=none; b=8C97uvjbwNZ8pOLr8CiL7un9IKeQzcSukyBEBvb6EydRzv8Wd44of6EcWVNYL0w6Efd3yU fXPHTr0Q10QHFt01ROUC8SWq2tIZdixNVSg0qAi0L04piSaXRkSExpe3dNkNkXWjvXmUq1 40stb6d4+4pyfYiVprZQTLVRGM0E8to= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JmgQnTSy; spf=pass (imf27.hostedemail.com: domain of will@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662718242; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=waejBwTqFQ2my3z+sV6tBeDtc85qY0Zki0zQyKWsDBI=; b=Ny/0Ym9MxSkIz/RqCv7iYacTsG+hQUxjxyExqhMlFGIpHT1i1ATEQatDrquX1Zwkvzn9sY OqK+I2GSQd+WdqE+T39k4bI8Wq+5Pr2Dy+5KPTWRk1mFivvFDb8PI/l6wHBmThDSJTgyud lK3olFlq/ZNZd/q096TiiI4fnUdOC00= Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JmgQnTSy; spf=pass (imf27.hostedemail.com: domain of will@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Queue-Id: B9864400D4 X-Rspamd-Server: rspam09 X-Stat-Signature: q47377ki43tjc391rxyf5oxx4u6ena96 X-HE-Tag: 1662718242-275081 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: On Fri, Sep 09, 2022 at 01:24:10AM +0300, Kirill A. Shutemov wrote: > On Thu, Sep 08, 2022 at 11:48:09PM +0300, Sergei Antonov wrote: > > Running this test program on ARMv4 a few times (sometimes just once) > > reproduces the bug. > > > > int main() > > { > > unsigned i; > > char paragon[SIZE]; > > void* ptr; > > > > memset(paragon, 0xAA, SIZE); > > ptr = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, > > MAP_ANON | MAP_SHARED, -1, 0); > > if (ptr == MAP_FAILED) return 1; > > printf("ptr = %p\n", ptr); > > for (i=0;i<10000;i++){ > > memset(ptr, 0xAA, SIZE); > > if (memcmp(ptr, paragon, SIZE)) { > > printf("Unexpected bytes on iteration %u!!!\n", i); > > break; > > } > > } > > munmap(ptr, SIZE); > > } > > > > In the "ptr" buffer there appear runs of zero bytes which are aligned > > by 16 and their lengths are multiple of 16. > > > > Linux v5.11 does not have the bug, "git bisect" finds the first bad commit: > > f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths") > > > > Before the commit update_mmu_cache() was called during a call to > > filemap_map_pages() as well as finish_fault(). After the commit > > finish_fault() lacks it. > > > > Bring back update_mmu_cache() to finish_fault() to fix the bug. > > Also call update_mmu_tlb() only when returning VM_FAULT_NOPAGE to more > > closely reproduce the code of alloc_set_pte() function that existed before > > the commit. > > > > On many platforms update_mmu_cache() is nop: > > x86, see arch/x86/include/asm/pgtable > > ARMv6+, see arch/arm/include/asm/tlbflush.h > > So, it seems, few users ran into this bug. > > > > Fixes: f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths") > > Signed-off-by: Sergei Antonov > > Cc: Kirill A. Shutemov > > +Will. > > Seems I confused update_mmu_tlb() with update_mmu_cache() :/ Urgh, that thing is pretty horrible! But anyway, I agree that this change looks correct based on the other callers in the file. > Looks good to me: > > Acked-by: Kirill A. Shutemov I'm assuming Andrew will pick this up. Otherwise, please let me know if I should route it via the arm64 tree. Will