public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation•org>
To: Max Krummenacher <max.oss.09@gmail•com>
Cc: Ard Biesheuvel <ardb@kernel•org>,
	Naresh Kamboju <naresh.kamboju@linaro•org>,
	Linux ARM <linux-arm-kernel@lists•infradead.org>,
	open list <linux-kernel@vger•kernel.org>,
	Linux-Next Mailing List <linux-next@vger•kernel.org>,
	lkft-triage@lists•linaro.org,
	Stephen Rothwell <sfr@canb•auug.org.au>,
	Russell King - ARM Linux <linux@armlinux•org.uk>,
	Arnd Bergmann <arnd@arndb•de>,
	max.krummenacher@toradex•com, Shawn Guo <shawnguo@kernel•org>,
	Stefano Stabellini <stefano.stabellini@xilinx•com>,
	Christoph Hellwig <hch@lst•de>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle•com>,
	"Eric W. Biederman" <ebiederm@xmission•com>
Subject: Re: [next] arm: boot failed - PC is at cpu_ca15_set_pte_ext
Date: Wed, 20 Apr 2022 14:53:25 -0700	[thread overview]
Message-ID: <20220420145325.602b45256b98c14c9325c61d@linux-foundation.org> (raw)
In-Reply-To: <9eb0c1a4f805a75e3e9f24dfcae3077b772a06c0.camel@gmail.com>

On Wed, 20 Apr 2022 09:50:52 +0200 Max Krummenacher <max.oss.09@gmail•com> 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 <peterx@redhat•com>
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 <peterx@redhat•com>
Reported-by: Marek Szyprowski <m.szyprowski@samsung•com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung•com>
Cc: Alistair Popple <apopple@nvidia•com>
Cc: Andrea Arcangeli <aarcange@redhat•com>
Cc: Axel Rasmussen <axelrasmussen@google•com>
Cc: David Hildenbrand <david@redhat•com>
Cc: Hugh Dickins <hughd@google•com>
Cc: Jerome Glisse <jglisse@redhat•com>
Cc: "Kirill A . Shutemov" <kirill@shutemov•name>
Cc: Matthew Wilcox <willy@infradead•org>
Cc: Mike Kravetz <mike.kravetz@oracle•com>
Cc: Mike Rapoport <rppt@linux•vnet.ibm.com>
Cc: Nadav Amit <nadav.amit@gmail•com>
Signed-off-by: Andrew Morton <akpm@linux-foundation•org>
---


--- 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,
_


  parent reply	other threads:[~2022-04-20 21:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 10:58 [next] arm: boot failed - PC is at cpu_ca15_set_pte_ext Naresh Kamboju
2022-04-19 18:57 ` Russell King (Oracle)
2022-04-20  8:55   ` Naresh Kamboju
2022-04-20  9:44     ` Russell King (Oracle)
2022-04-20  7:31 ` Ard Biesheuvel
2022-04-20  7:50   ` Max Krummenacher
2022-04-20 13:04     ` Naresh Kamboju
2022-04-20 21:53     ` Andrew Morton [this message]
2022-04-20  8:54   ` Naresh Kamboju

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220420145325.602b45256b98c14c9325c61d@linux-foundation.org \
    --to=akpm@linux-foundation$(echo .)org \
    --cc=ardb@kernel$(echo .)org \
    --cc=arnd@arndb$(echo .)de \
    --cc=ebiederm@xmission$(echo .)com \
    --cc=hch@lst$(echo .)de \
    --cc=konrad.wilk@oracle$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=linux@armlinux$(echo .)org.uk \
    --cc=lkft-triage@lists$(echo .)linaro.org \
    --cc=max.krummenacher@toradex$(echo .)com \
    --cc=max.oss.09@gmail$(echo .)com \
    --cc=naresh.kamboju@linaro$(echo .)org \
    --cc=sfr@canb$(echo .)auug.org.au \
    --cc=shawnguo@kernel$(echo .)org \
    --cc=stefano.stabellini@xilinx$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox