Message ID | 20230524131238.2791-1-jszhang@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2846558vqo; Wed, 24 May 2023 06:26:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QldA1+a39+4kp7Nmpegz4p7vdZd1YJ2nEraMJmbXgZcJw9wkgNS/5yO6Vl4S0jlJnL3ry X-Received: by 2002:a17:90a:ead8:b0:252:ad83:5907 with SMTP id ev24-20020a17090aead800b00252ad835907mr17221329pjb.16.1684934764096; Wed, 24 May 2023 06:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684934764; cv=none; d=google.com; s=arc-20160816; b=R5+LMFBnLXSdxBhd/qzx+opit2Wg1AGY0Jnj0FO7+5w9gWPcpMNJ1wHCzIue8EaDgu 4doJtmE387dDctNeHTDejRONBCmj+LUvXa2MdtMg9ZKAHm7RoaI5He1Vl58vzyp1yUc6 wlq3qtY3wZhAKsdNsRagwihtZEo+6A/wOLV/Tkb92hLJTfDA3lPB3sK9SIZFu1TLjp8R kqZIuqdVG8lGmZLfg8a2RKAn1tCaM+nGWPyPm71uU0vcLi3fw26mIzk/SFd0gT6dR/yK IM/O0EJrye3A8sMmJcGl6B2A8ffdksaN4N1p50o66U96te+vdKwr7hQeCw2/ov7iBG2f fjZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/Th1ctDRpxE0P7ABTcNoA1LkITiN+vWmEjWb5uTgEEU=; b=yLFeblx21BP0MU/9mRfZdNrpHr3ynOt6O1fl92FBanwwXdXcFEd+iOtwwMVIqjc0ou CRHOttZSAdXPSm0aIUfDAwUV2Jnr16+80xjOEiHsQaYJ675JcEl6dfqHZiiRz/Y6qdLp t1XYg7pHALGhsiYZM/CgrcHN8v5yzGW+q96RdMHQ5iGrOEBqX1UvcYb57YuZufe5rWg2 TDz3CkCcc/IJvapI6xRj8vm8Ugokm93sI+vE1RtNuy/HVNpWtJjxAE3OpyGKxj6f63L+ J9TZtLm82UF8+WKbPlPqAC82UusVUHN6SBNNG+m9V8LaCKvJtxIzPYFb46y7xjASRJm9 XLHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ReE/FBJx"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gz21-20020a17090b0ed500b0024e140702efsi184151pjb.118.2023.05.24.06.25.47; Wed, 24 May 2023 06:26: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="ReE/FBJx"; 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 S232270AbjEXNYN (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Wed, 24 May 2023 09:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233936AbjEXNXy (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 24 May 2023 09:23:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A26CAB6 for <linux-kernel@vger.kernel.org>; Wed, 24 May 2023 06:23:53 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1ADFA63351 for <linux-kernel@vger.kernel.org>; Wed, 24 May 2023 13:23:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69F55C4339B; Wed, 24 May 2023 13:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684934630; bh=X7w8UNBEZj68xoYR2+1fzYHN1lzC2y2GrI0EwehDjsk=; h=From:To:Cc:Subject:Date:From; b=ReE/FBJxbcHETmpMLAuM2/2+fMFJHxShGyb9I//gEdE3yoh1i66mXLpb+Tv8VyHEG gNbmYcVBfAtbSUsAkSCioYsC5k/GcC7C66aZh52EEvU0Fn9OB8ehms4oN5/XNhj2Tu T7D2mgDY+rvDwYZq7VVGB1ZjBDNCDmt7BHVvEZmmopNVUrp3K4tIiqHwH5+nbESsKv j7alRZUjfI8OKlopPSzj5I4KyFKOrdkBVio5ToZgvbPAQqO0NAlMxdqq7Dy0wttHVm x35sdP5Ih9qWPQAtlPy29CsFDuf55qH+VbK7dGXvwTu2AYMgiTBEL9x84iMM8MqznA rNABVyRoPWUKA== From: Jisheng Zhang <jszhang@kernel.org> To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org> Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block Date: Wed, 24 May 2023 21:12:38 +0800 Message-Id: <20230524131238.2791-1-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766782155154189227?= X-GMAIL-MSGID: =?utf-8?q?1766782155154189227?= |
Series |
arm64: mm: pass original fault address to handle_mm_fault() in PER_VMA_LOCK block
|
|
Commit Message
Jisheng Zhang
May 24, 2023, 1:12 p.m. UTC
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(-)
Comments
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
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
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)) {
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)) {