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 X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6955BC433E2 for ; Tue, 7 Jul 2020 22:50:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 25C5420720 for ; Tue, 7 Jul 2020 22:50:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BYDbYeDi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25C5420720 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DDD096B00A6; Tue, 7 Jul 2020 18:50:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB3096B00AD; Tue, 7 Jul 2020 18:50:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86B346B00AB; Tue, 7 Jul 2020 18:50:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 6A79D6B00AA for ; Tue, 7 Jul 2020 18:50:36 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 269098248D52 for ; Tue, 7 Jul 2020 22:50:36 +0000 (UTC) X-FDA: 77012775672.02.unit63_2f0cf5a26eb8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 41C73300015DA0AD for ; Tue, 7 Jul 2020 22:50:35 +0000 (UTC) X-HE-Tag: unit63_2f0cf5a26eb8 X-Filterd-Recvd-Size: 6873 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jul 2020 22:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594162234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D8OdeaID5or5gsgcWoj3vmPJjBIrXv0E7kOuYlamE1o=; b=BYDbYeDifz4xr+sRdXt1gwUCDKmkKvDdy8yeJngROdZJAVXBkdg4AAOE6ftLgwSyux8OQ7 SrfhSU13oP1cWX5I01ORWCHuGA/UZc6fk7DSa7f4HPkEM+Rb+OnosC0JjD/Zg8PYHsBZZz Pslg/on154o0uxT40/u1w3Uvg/jXbIY= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-179-TmbW4exeORufj-taLA6c3w-1; Tue, 07 Jul 2020 18:50:31 -0400 X-MC-Unique: TmbW4exeORufj-taLA6c3w-1 Received: by mail-qt1-f198.google.com with SMTP id k9so5983140qth.17 for ; Tue, 07 Jul 2020 15:50:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D8OdeaID5or5gsgcWoj3vmPJjBIrXv0E7kOuYlamE1o=; b=d0GHMLJDc1uXjNz8ZWljeO5c9j06loWqP/zmCKaKMmyAJXWmKL7MLpPpXxdOc07KQS O5/HKsgpN2cMefZ+3WMVga8ad7rNUb/PUzMa0lcE5O2OHEtRzQCWgJ8rrFbDwG0CRVA9 1qBJJu/skY0gU5oikluc88WmgejAMHfrN+QPMIpKO/fCeRMX5SJIAoe48d/s3IoJocKd sgliuXOm31SqO/lWlwcScc4L6OPbNQXZmyOAwjNr/vBj18YrknyM+aIWJmjp6R8yDrhO 4IVZXYepkxXRtvbln+ghPTEfG9cLeNJqM2uDN3biONWrjEV8yz5cBZ1U9fZsCYBBfJbK RCfQ== X-Gm-Message-State: AOAM531EmVcDwCFTzNATe2t84p5o6tShyJuyyrktAfTK8b2TAE6g/TBh 72i8etxRAp71ahrugfqgtHZrYJvtWse0LErFzFJozlor0hAXBHXQD2JNT/CU3ygJ5yeDVaeD8L0 8BXwKGwbXq4A= X-Received: by 2002:ac8:4419:: with SMTP id j25mr59295040qtn.0.1594162231217; Tue, 07 Jul 2020 15:50:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz8DXKkHPxoOFEcQD6pHkWkgMOJfaMYF0tKBmTSmaZQNpqDRHsJem4bnZngb+YYMsixKQJtw== X-Received: by 2002:ac8:4419:: with SMTP id j25mr59295024qtn.0.1594162230982; Tue, 07 Jul 2020 15:50:30 -0700 (PDT) Received: from xz-x1.redhat.com ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id j16sm26267642qtp.92.2020.07.07.15.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 15:50:30 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Gerald Schaefer , Linus Torvalds , peterx@redhat.com, Andrew Morton , Will Deacon , Andrea Arcangeli , David Rientjes , John Hubbard , Michael Ellerman , Russell King , linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 04/25] mm/arm: Use general page fault accounting Date: Tue, 7 Jul 2020 18:50:00 -0400 Message-Id: <20200707225021.200906-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707225021.200906-1-peterx@redhat.com> References: <20200707225021.200906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 41C73300015DA0AD X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the general page fault accounting by passing regs into handle_mm_faul= t(). It naturally solve the issue of multiple page fault accounting when page = fault retry happened. To do this, we need to pass the pt_regs pointer into __do_page_fault(). Fix PERF_COUNT_SW_PAGE_FAULTS perf event manually for page fault retries,= by moving it before taking mmap_sem. CC: Russell King CC: Will Deacon CC: linux-arm-kernel@lists.infradead.org Signed-off-by: Peter Xu --- arch/arm/mm/fault.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 01a8e0f8fef7..efa402025031 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -202,7 +202,8 @@ static inline bool access_error(unsigned int fsr, str= uct vm_area_struct *vma) =20 static vm_fault_t __kprobes __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int f= sr, - unsigned int flags, struct task_struct *tsk) + unsigned int flags, struct task_struct *tsk, + struct pt_regs *regs) { struct vm_area_struct *vma; vm_fault_t fault; @@ -224,7 +225,7 @@ __do_page_fault(struct mm_struct *mm, unsigned long a= ddr, unsigned int fsr, goto out; } =20 - return handle_mm_fault(vma, addr & PAGE_MASK, flags, NULL); + return handle_mm_fault(vma, addr & PAGE_MASK, flags, regs); =20 check_stack: /* Don't allow expansion below FIRST_USER_ADDRESS */ @@ -266,6 +267,8 @@ do_page_fault(unsigned long addr, unsigned int fsr, s= truct pt_regs *regs) if ((fsr & FSR_WRITE) && !(fsr & FSR_CM)) flags |=3D FAULT_FLAG_WRITE; =20 + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); + /* * As per x86, we may deadlock here. However, since the kernel only * validly references user space from well defined areas of the code, @@ -290,7 +293,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, s= truct pt_regs *regs) #endif } =20 - fault =3D __do_page_fault(mm, addr, fsr, flags, tsk); + fault =3D __do_page_fault(mm, addr, fsr, flags, tsk, regs); =20 /* If we need to retry but a fatal signal is pending, handle the * signal first. We do not need to release the mmap_lock because @@ -302,23 +305,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, = struct pt_regs *regs) return 0; } =20 - /* - * Major/minor page fault accounting is only done on the - * initial attempt. If we go through a retry, it is extremely - * likely that the page will be found in page cache at that point. - */ - - perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); if (!(fault & VM_FAULT_ERROR) && flags & FAULT_FLAG_ALLOW_RETRY) { - if (fault & VM_FAULT_MAJOR) { - tsk->maj_flt++; - perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, - regs, addr); - } else { - tsk->min_flt++; - perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, - regs, addr); - } if (fault & VM_FAULT_RETRY) { flags |=3D FAULT_FLAG_TRIED; goto retry; --=20 2.26.2