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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCBBCC433F5 for ; Wed, 20 Apr 2022 21:53:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382703AbiDTV4S (ORCPT ); Wed, 20 Apr 2022 17:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236516AbiDTV4R (ORCPT ); Wed, 20 Apr 2022 17:56:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCAB945513; Wed, 20 Apr 2022 14:53:29 -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 7BB0EB821B0; Wed, 20 Apr 2022 21:53:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA5B1C385A0; Wed, 20 Apr 2022 21:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1650491607; bh=s+1aSxlHOsrj2r/dbmg/La17ENCktIGI5EcH703yDBc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Hu+OnO1lFWn0QE4re9JajSeGmR5kc3K1HYS0x0FiHx6jDoziq07AlVY5PEFh5BjgS Rm2DTG+CDczCpPcm554B8IQhnTa+tpdLZWulhnB8jlTzzk6CP8OfXszgO9DIB6xc+S uwnsNhQI+uwo2WH/xQPSe4cE5602DcO9CUVattq8= Date: Wed, 20 Apr 2022 14:53:25 -0700 From: Andrew Morton To: Max Krummenacher Cc: Ard Biesheuvel , Naresh Kamboju , Linux ARM , open list , Linux-Next Mailing List , lkft-triage@lists.linaro.org, Stephen Rothwell , Russell King - ARM Linux , Arnd Bergmann , max.krummenacher@toradex.com, Shawn Guo , Stefano Stabellini , Christoph Hellwig , Konrad Rzeszutek Wilk , "Eric W. Biederman" Subject: Re: [next] arm: boot failed - PC is at cpu_ca15_set_pte_ext Message-Id: <20220420145325.602b45256b98c14c9325c61d@linux-foundation.org> In-Reply-To: <9eb0c1a4f805a75e3e9f24dfcae3077b772a06c0.camel@gmail.com> References: <9eb0c1a4f805a75e3e9f24dfcae3077b772a06c0.camel@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Apr 2022 09:50:52 +0200 Max Krummenacher wrote: > > > > Unfortunately, the vmlinux.xz file I downloaded from the link below > > seems to be different from the one that produced the crash, given that > > the LR address of c04cfeb8 does not seem to correspond with > > handle_mm_fault+0x60c/0xed0. > > > > Can you please double check the artifacts? > > Commit "mm: check against orig_pte for finish_fault()" introduced this, > i.e. on yesterdays next reverting a066bab3c0eb made a i.MX6 boot again. > A fix is discussed here: > > https://lore.kernel.org/all/YliNP7ADcdc4Puvs@xz-m1.local/ > Thanks for finding that. I have Peter's fix queued and shall push out a snapshot later today, for integration into linux-next. From: Peter Xu Subject: mm-check-against-orig_pte-for-finish_fault-fix fix crash reported by Marek Link: https://lkml.kernel.org/r/Ylb9rXJyPm8/ao8f@xz-m1.local Signed-off-by: Peter Xu Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski Cc: Alistair Popple Cc: Andrea Arcangeli Cc: Axel Rasmussen Cc: David Hildenbrand Cc: Hugh Dickins Cc: Jerome Glisse Cc: "Kirill A . Shutemov" Cc: Matthew Wilcox Cc: Mike Kravetz Cc: Mike Rapoport Cc: Nadav Amit Signed-off-by: Andrew Morton --- --- a/include/linux/mm_types.h~mm-check-against-orig_pte-for-finish_fault-fix +++ a/include/linux/mm_types.h @@ -814,6 +814,8 @@ typedef struct { * @FAULT_FLAG_UNSHARE: The fault is an unsharing request to unshare (and mark * exclusive) a possibly shared anonymous page that is * mapped R/O. + * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached. + * We should only access orig_pte if this flag set. * * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify * whether we would allow page faults to retry by specifying these two @@ -850,6 +852,7 @@ enum fault_flag { FAULT_FLAG_INSTRUCTION = 1 << 8, FAULT_FLAG_INTERRUPTIBLE = 1 << 9, FAULT_FLAG_UNSHARE = 1 << 10, + FAULT_FLAG_ORIG_PTE_VALID = 1 << 11, }; #endif /* _LINUX_MM_TYPES_H */ --- a/mm/memory.c~mm-check-against-orig_pte-for-finish_fault-fix +++ a/mm/memory.c @@ -4194,6 +4194,15 @@ void do_set_pte(struct vm_fault *vmf, st set_pte_at(vma->vm_mm, addr, vmf->pte, entry); } +static bool vmf_pte_changed(struct vm_fault *vmf) +{ + if (vmf->flags & FAULT_FLAG_ORIG_PTE_VALID) { + return !pte_same(*vmf->pte, vmf->orig_pte); + } + + return !pte_none(*vmf->pte); +} + /** * finish_fault - finish page fault once we have prepared the page to fault * @@ -4252,7 +4261,7 @@ vm_fault_t finish_fault(struct vm_fault vmf->address, &vmf->ptl); ret = 0; /* Re-check under ptl */ - if (likely(pte_same(*vmf->pte, vmf->orig_pte))) + if (likely(!vmf_pte_changed(vmf))) do_set_pte(vmf, page, vmf->address); else ret = VM_FAULT_NOPAGE; @@ -4720,13 +4729,7 @@ static vm_fault_t handle_pte_fault(struc * concurrent faults and from rmap lookups. */ vmf->pte = NULL; - /* - * Always initialize orig_pte. This matches with below - * code to have orig_pte to be the none pte if pte==NULL. - * This makes the rest code to be always safe to reference - * it, e.g. in finish_fault() we'll detect pte changes. - */ - pte_clear(vmf->vma->vm_mm, vmf->address, &vmf->orig_pte); + vmf->flags &= ~FAULT_FLAG_ORIG_PTE_VALID; } else { /* * If a huge pmd materialized under us just retry later. Use @@ -4750,6 +4753,7 @@ static vm_fault_t handle_pte_fault(struc */ vmf->pte = pte_offset_map(vmf->pmd, vmf->address); vmf->orig_pte = *vmf->pte; + vmf->flags |= FAULT_FLAG_ORIG_PTE_VALID; /* * some architectures can have larger ptes than wordsize, _