linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
@ 2023-05-24 13:12 Jisheng Zhang
  2023-05-24 13:26 ` Jisheng Zhang
  2023-05-25  7:00 ` Anshuman Khandual
  0 siblings, 2 replies; 7+ messages in thread
From: Jisheng Zhang @ 2023-05-24 13:12 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, linux-kernel

When reading the arm64's PER_VMA_LOCK support code, I found a bit
difference between arm64 and other arch when calling handle_mm_fault()
during VMA lock-based page fault handling: the fault address is masked
before passing to handle_mm_fault(). This is also different from the
usage in mmap_lock-based handling. I think we need to pass the
original fault address to handle_mm_fault() as we did in
commit 84c5e23edecd ("arm64: mm: Pass original fault address to
handle_mm_fault()").

If we go through the code path further, we can find that the "masked"
fault address can cause mismatched fault address between perf sw
major/minor page fault sw event and perf page fault sw event:

do_page_fault
  perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, ..., addr)   // orig addr
  handle_mm_fault
    mm_account_fault
      perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, ...) // masked addr

Fixes: cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first")
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 arch/arm64/mm/fault.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index cb21ccd7940d..6045a5117ac1 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -600,8 +600,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 		vma_end_read(vma);
 		goto lock_mmap;
 	}
-	fault = handle_mm_fault(vma, addr & PAGE_MASK,
-				mm_flags | FAULT_FLAG_VMA_LOCK, regs);
+	fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs);
 	vma_end_read(vma);
 
 	if (!(fault & VM_FAULT_RETRY)) {
-- 
2.40.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
@ 2023-05-24 13:13 Jisheng Zhang
  2023-05-25 17:03 ` Catalin Marinas
  2023-06-02 12:33 ` Will Deacon
  0 siblings, 2 replies; 7+ messages in thread
From: Jisheng Zhang @ 2023-05-24 13:13 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: linux-arm-kernel, linux-kernel, Suren Baghdasaryan

When reading the arm64's PER_VMA_LOCK support code, I found a bit
difference between arm64 and other arch when calling handle_mm_fault()
during VMA lock-based page fault handling: the fault address is masked
before passing to handle_mm_fault(). This is also different from the
usage in mmap_lock-based handling. I think we need to pass the
original fault address to handle_mm_fault() as we did in
commit 84c5e23edecd ("arm64: mm: Pass original fault address to
handle_mm_fault()").

If we go through the code path further, we can find that the "masked"
fault address can cause mismatched fault address between perf sw
major/minor page fault sw event and perf page fault sw event:

do_page_fault
  perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, ..., addr)   // orig addr
  handle_mm_fault
    mm_account_fault
      perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, ...) // masked addr

Fixes: cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first")
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
 arch/arm64/mm/fault.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index cb21ccd7940d..6045a5117ac1 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -600,8 +600,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 		vma_end_read(vma);
 		goto lock_mmap;
 	}
-	fault = handle_mm_fault(vma, addr & PAGE_MASK,
-				mm_flags | FAULT_FLAG_VMA_LOCK, regs);
+	fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs);
 	vma_end_read(vma);
 
 	if (!(fault & VM_FAULT_RETRY)) {
-- 
2.40.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
  2023-05-24 13:12 [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block Jisheng Zhang
@ 2023-05-24 13:26 ` Jisheng Zhang
  2023-05-24 14:39   ` Suren Baghdasaryan
  2023-05-25  7:00 ` Anshuman Khandual
  1 sibling, 1 reply; 7+ messages in thread
From: Jisheng Zhang @ 2023-05-24 13:26 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon; +Cc: linux-arm-kernel, linux-kernel

On Wed, May 24, 2023 at 09:12:38PM +0800, Jisheng Zhang wrote:
> When reading the arm64's PER_VMA_LOCK support code, I found a bit
> difference between arm64 and other arch when calling handle_mm_fault()
> during VMA lock-based page fault handling: the fault address is masked
> before passing to handle_mm_fault(). This is also different from the
> usage in mmap_lock-based handling. I think we need to pass the
> original fault address to handle_mm_fault() as we did in
> commit 84c5e23edecd ("arm64: mm: Pass original fault address to
> handle_mm_fault()").
> 
> If we go through the code path further, we can find that the "masked"
> fault address can cause mismatched fault address between perf sw
> major/minor page fault sw event and perf page fault sw event:

OOPS, sorry please ignore this one. I pressed ctrl-c to interrupt the
git send-mail, but it's still sent out ;)

Instead, let's focus on
https://lore.kernel.org/linux-arm-kernel/20230524131305.2808-1-jszhang@kernel.org/T/#u

The two patches are the same, I just added Suren into CC list.

> 
> do_page_fault
>   perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, ..., addr)   // orig addr
>   handle_mm_fault
>     mm_account_fault
>       perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, ...) // masked addr
> 
> Fixes: cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first")
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
>  arch/arm64/mm/fault.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> index cb21ccd7940d..6045a5117ac1 100644
> --- a/arch/arm64/mm/fault.c
> +++ b/arch/arm64/mm/fault.c
> @@ -600,8 +600,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
>  		vma_end_read(vma);
>  		goto lock_mmap;
>  	}
> -	fault = handle_mm_fault(vma, addr & PAGE_MASK,
> -				mm_flags | FAULT_FLAG_VMA_LOCK, regs);
> +	fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs);
>  	vma_end_read(vma);
>  
>  	if (!(fault & VM_FAULT_RETRY)) {
> -- 
> 2.40.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
  2023-05-24 13:26 ` Jisheng Zhang
@ 2023-05-24 14:39   ` Suren Baghdasaryan
  0 siblings, 0 replies; 7+ messages in thread
From: Suren Baghdasaryan @ 2023-05-24 14:39 UTC (permalink / raw)
  To: Jisheng Zhang
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel

On Wed, May 24, 2023 at 6:38 AM Jisheng Zhang <jszhang@kernel.org> wrote:
>
> On Wed, May 24, 2023 at 09:12:38PM +0800, Jisheng Zhang wrote:
> > When reading the arm64's PER_VMA_LOCK support code, I found a bit
> > difference between arm64 and other arch when calling handle_mm_fault()
> > during VMA lock-based page fault handling: the fault address is masked
> > before passing to handle_mm_fault(). This is also different from the
> > usage in mmap_lock-based handling. I think we need to pass the
> > original fault address to handle_mm_fault() as we did in
> > commit 84c5e23edecd ("arm64: mm: Pass original fault address to
> > handle_mm_fault()").

Thanks for noticing. I'm not sure why this masking leaked into my
patch. I don't think I wrote it before 84c5e23edecd was merged in June
2021.
Anyway, your assessment looks correct to me.

> >
> > If we go through the code path further, we can find that the "masked"
> > fault address can cause mismatched fault address between perf sw
> > major/minor page fault sw event and perf page fault sw event:
>
> OOPS, sorry please ignore this one. I pressed ctrl-c to interrupt the
> git send-mail, but it's still sent out ;)
>
> Instead, let's focus on
> https://lore.kernel.org/linux-arm-kernel/20230524131305.2808-1-jszhang@kernel.org/T/#u
>
> The two patches are the same, I just added Suren into CC list.
>
> >
> > do_page_fault
> >   perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, ..., addr)   // orig addr
> >   handle_mm_fault
> >     mm_account_fault
> >       perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, ...) // masked addr
> >
> > Fixes: cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first")
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>

Reviewed-by: Suren Baghdasaryan <surenb@google.com>

> > ---
> >  arch/arm64/mm/fault.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> > index cb21ccd7940d..6045a5117ac1 100644
> > --- a/arch/arm64/mm/fault.c
> > +++ b/arch/arm64/mm/fault.c
> > @@ -600,8 +600,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
> >               vma_end_read(vma);
> >               goto lock_mmap;
> >       }
> > -     fault = handle_mm_fault(vma, addr & PAGE_MASK,
> > -                             mm_flags | FAULT_FLAG_VMA_LOCK, regs);
> > +     fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs);
> >       vma_end_read(vma);
> >
> >       if (!(fault & VM_FAULT_RETRY)) {
> > --
> > 2.40.1
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
  2023-05-24 13:12 [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block Jisheng Zhang
  2023-05-24 13:26 ` Jisheng Zhang
@ 2023-05-25  7:00 ` Anshuman Khandual
  1 sibling, 0 replies; 7+ messages in thread
From: Anshuman Khandual @ 2023-05-25  7:00 UTC (permalink / raw)
  To: Jisheng Zhang, Catalin Marinas, Will Deacon
  Cc: linux-arm-kernel, linux-kernel



On 5/24/23 18:42, Jisheng Zhang wrote:
> When reading the arm64's PER_VMA_LOCK support code, I found a bit
> difference between arm64 and other arch when calling handle_mm_fault()
> during VMA lock-based page fault handling: the fault address is masked
> before passing to handle_mm_fault(). This is also different from the
> usage in mmap_lock-based handling. I think we need to pass the
> original fault address to handle_mm_fault() as we did in
> commit 84c5e23edecd ("arm64: mm: Pass original fault address to
> handle_mm_fault()").
> 
> If we go through the code path further, we can find that the "masked"
> fault address can cause mismatched fault address between perf sw
> major/minor page fault sw event and perf page fault sw event:
> 
> do_page_fault
>   perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, ..., addr)   // orig addr
>   handle_mm_fault
>     mm_account_fault
>       perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, ...) // masked addr
> 
> Fixes: cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first")
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>

LGTM

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

> ---
>  arch/arm64/mm/fault.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
> index cb21ccd7940d..6045a5117ac1 100644
> --- a/arch/arm64/mm/fault.c
> +++ b/arch/arm64/mm/fault.c
> @@ -600,8 +600,7 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
>  		vma_end_read(vma);
>  		goto lock_mmap;
>  	}
> -	fault = handle_mm_fault(vma, addr & PAGE_MASK,
> -				mm_flags | FAULT_FLAG_VMA_LOCK, regs);
> +	fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs);
>  	vma_end_read(vma);
>  
>  	if (!(fault & VM_FAULT_RETRY)) {

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
  2023-05-24 13:13 Jisheng Zhang
@ 2023-05-25 17:03 ` Catalin Marinas
  2023-06-02 12:33 ` Will Deacon
  1 sibling, 0 replies; 7+ messages in thread
From: Catalin Marinas @ 2023-05-25 17:03 UTC (permalink / raw)
  To: Jisheng Zhang
  Cc: Will Deacon, linux-arm-kernel, linux-kernel, Suren Baghdasaryan

On Wed, May 24, 2023 at 09:13:05PM +0800, Jisheng Zhang wrote:
> When reading the arm64's PER_VMA_LOCK support code, I found a bit
> difference between arm64 and other arch when calling handle_mm_fault()
> during VMA lock-based page fault handling: the fault address is masked
> before passing to handle_mm_fault(). This is also different from the
> usage in mmap_lock-based handling. I think we need to pass the
> original fault address to handle_mm_fault() as we did in
> commit 84c5e23edecd ("arm64: mm: Pass original fault address to
> handle_mm_fault()").
> 
> If we go through the code path further, we can find that the "masked"
> fault address can cause mismatched fault address between perf sw
> major/minor page fault sw event and perf page fault sw event:
> 
> do_page_fault
>   perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, ..., addr)   // orig addr
>   handle_mm_fault
>     mm_account_fault
>       perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, ...) // masked addr
> 
> Fixes: cd7f176aea5f ("arm64/mm: try VMA lock-based page fault handling first")
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
  2023-05-24 13:13 Jisheng Zhang
  2023-05-25 17:03 ` Catalin Marinas
@ 2023-06-02 12:33 ` Will Deacon
  1 sibling, 0 replies; 7+ messages in thread
From: Will Deacon @ 2023-06-02 12:33 UTC (permalink / raw)
  To: Catalin Marinas, Jisheng Zhang
  Cc: kernel-team, Will Deacon, Suren Baghdasaryan, linux-kernel,
	linux-arm-kernel

On Wed, 24 May 2023 21:13:05 +0800, Jisheng Zhang wrote:
> When reading the arm64's PER_VMA_LOCK support code, I found a bit
> difference between arm64 and other arch when calling handle_mm_fault()
> during VMA lock-based page fault handling: the fault address is masked
> before passing to handle_mm_fault(). This is also different from the
> usage in mmap_lock-based handling. I think we need to pass the
> original fault address to handle_mm_fault() as we did in
> commit 84c5e23edecd ("arm64: mm: Pass original fault address to
> handle_mm_fault()").
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
      https://git.kernel.org/arm64/c/0e2aba694866

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-06-02 12:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-24 13:12 [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block Jisheng Zhang
2023-05-24 13:26 ` Jisheng Zhang
2023-05-24 14:39   ` Suren Baghdasaryan
2023-05-25  7:00 ` Anshuman Khandual
  -- strict thread matches above, loose matches on Subject: below --
2023-05-24 13:13 Jisheng Zhang
2023-05-25 17:03 ` Catalin Marinas
2023-06-02 12:33 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).