Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1740980rwn; Fri, 9 Sep 2022 03:25:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR7YkFZbNJbEGuaTP7efACvER5Hmkl0H05W6qmTDo/O4MC+uv2FCCRFhGzyGVrj8YQiDawk7 X-Received: by 2002:a2e:3006:0:b0:266:6677:5125 with SMTP id w6-20020a2e3006000000b0026666775125mr4112822ljw.352.1662719104747; Fri, 09 Sep 2022 03:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662719104; cv=none; d=google.com; s=arc-20160816; b=xqJ5vhYL10k1Ts9Az5jxvZlMcuDgRXtPOPj/VRllk2ENWDj4VeThpTBF5RJNFj996I 1xSMyYLNi2HWdQ0Fmyd4kAlE0acfkQEzar4GsJeF5Dba6JVMSTmPAxtYpd/3X90UFL3b RGuN79PbxmsneBQQvRSF/ehLL4Bf4gLv23jG3xJnPdjF9puzegmU+mkLO04O9ybbanuh AamEfUmUzlkmnco0AoF+Tedxyxzf1UJS/CrPACml3WSFfedPafqI7yJm25B4NKLBGQe5 0eMOttaHc06F+/JpiB+B1m04hm+AmGr9WGpZiruU/3WOC9BBrNB+RN39JdHD0LNXsdKi Fm2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=waejBwTqFQ2my3z+sV6tBeDtc85qY0Zki0zQyKWsDBI=; b=s10iE0Fv3uciwTjnLBu7fMghykADsNaLnNFz2pDVvDKzymkqq17HsMq9Pe7zL0Xa2g SZ/mzn1BK05VviXVYg37IzoklJy92DtkZQb2jtZQN3B0oYvt+VVdpsoXYKeQ2W0nXVv4 LE6DhfSVPi2Kbaxy7tfcHb+vzrb24XFyWdpKAL442j5TTYKBa/Ku9J+5omOIc09c7Bmt WbkmokYhOBRDoDu19xJk+H5a0Yhp9VHgHPXa0T53t5ud4dtoZMcCsZYwBhPQp7Xqh6UJ Se95g9mu9nDJO91+PgTDiO2KvyTm4AsyKo9vRhtyL94Uvl/z2z8+ur3fWe1jMgkgDwOh czWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JmgQnTSy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a056512318500b004869864ceeesi76747lfe.141.2022.09.09.03.24.34; Fri, 09 Sep 2022 03:25:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JmgQnTSy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbiIIKK7 (ORCPT + 99 others); Fri, 9 Sep 2022 06:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230257AbiIIKKq (ORCPT ); Fri, 9 Sep 2022 06:10:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7678E32AAD; Fri, 9 Sep 2022 03:10:42 -0700 (PDT) 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 D279AB8248A; 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) X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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