From patchwork Fri Apr 14 17:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13211887 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EABA4C77B72 for ; Fri, 14 Apr 2023 17:54:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E7606B0075; Fri, 14 Apr 2023 13:54:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BD966B0078; Fri, 14 Apr 2023 13:54:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7ACBC6B007B; Fri, 14 Apr 2023 13:54:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 683046B0075 for ; Fri, 14 Apr 2023 13:54:51 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 34FFB802E3 for ; Fri, 14 Apr 2023 17:54:51 +0000 (UTC) X-FDA: 80680747182.15.EBF66BC Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 87BC140014 for ; Fri, 14 Apr 2023 17:54:49 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=g9SpJgAT; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3aJM5ZAYKCJ0PROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3aJM5ZAYKCJ0PROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681494889; h=from:from:sender: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:in-reply-to: references:dkim-signature; bh=sxtuJlZyuhJWBSe3BUp1o+R468Jyg7wjt5EQDKL8liw=; b=Dr696ZeIHSY42HF1oXCCgvjdI7wXZoPYbdeq6+4R+Ve8MF+Tw7iTaqXZirHwvmO6R1v3rw 6H7JCOTZViEqrnMeQv+IX5m7YVqwwYRpRXlKI3rEcKMq8pGGGrkijqRbSbmlPnxhQlwUbT zxxQS0ieqf0v/lZza3ZUlZH+oc88Q/0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=g9SpJgAT; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3aJM5ZAYKCJ0PROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3aJM5ZAYKCJ0PROBK8DLLDIB.9LJIFKRU-JJHS79H.LOD@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681494889; a=rsa-sha256; cv=none; b=SB86hHQpMTHfevVvB47M8/hwWDUMlcnPmIDHvrBsbfzxwTl9i+ej9c4f8qUAIu7bHLsoqe 3ND58Lt+JlI5FnWHa4DdZXfnjFV9IFHkVNH/DJ4sNT3vxJIOROeJqcPrv/XXVUin2+K8nP nAQWybfhosXWwE4BX7H0hrA5Hi9BgMI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-54faf2e22afso83014617b3.7 for ; Fri, 14 Apr 2023 10:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681494888; x=1684086888; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=sxtuJlZyuhJWBSe3BUp1o+R468Jyg7wjt5EQDKL8liw=; b=g9SpJgATsQDIYrkaPJd8d+PpBLT6jxYfne0OaHPIARm2IOQH+5ZUzrk668RVIdTFIK sxOkrjHFb2IwJhV+Rhhqr+Ms2OhPNi3AodJ+9OY+2GG2/dSng1wTYMa57UFr7FfZAVxI Mjh/iCg/xVEVvZMZlFypxHv6CoV31SltYbDHcAJCNrxBVXuHnfWdWgPZy7WTw1rRq2XX TXhZzJwJ3E/Ie4KgOXvM9CGQPa5RcER+MZF/7gxO1S4H4wu9t0bNr4IGAKdJ6Cqg7aGH BaxrJvra46EdXACNO7xHjaZO0BZXtOmHgL+PMxZE4/oVvLRUiP56FT8IvxbimldOWzpD U8NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681494888; x=1684086888; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sxtuJlZyuhJWBSe3BUp1o+R468Jyg7wjt5EQDKL8liw=; b=Mhij5xJnG19BzIzMsovNNrm38qjdNL1CKPS72QkD+npnKDqqScklCtYXTj8ITO/lpv cCBImmue+rYb46rPmFItVOzUvfKs6+mjvcGVR5MPyGauADwfFOynuGhXYL4WiRh/vQBP 6ukkDEtoQlx/8YTLLT1nm2vsOLcJ1EIeLhkciAxj+l5JQBZsjd8vE7xoIwvk40dQTRaR yTNbZO/hw0L7ULx8wwk0vVyBnfl19SH8U6KyW5WtVhOTlUjYtRFem1ebDFPPeZEuQBpX FFfq4eoBlnxvJOyido+6TBJYoHZWeOooewxdABP04TFSmqRzmV+XR0at39tvyYaSYcqJ a3Cw== X-Gm-Message-State: AAQBX9faTCng4AN/whhJrjNaf3QCXAeMyILSfhaqkpZk0k7QV3QxnNbH eGqidlCfA2hv01Cr8sbgJfHPcVUJUPo= X-Google-Smtp-Source: AKy350avB5MCJ6AGQUDi4bXHuLqjAuOo0YGWC/cK9hfJMcJckV+n+dWeR6kBIWjZnXn/yq9bCXOysK/QEQk= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:46c0:7584:f020:e09f]) (user=surenb job=sendgmr) by 2002:a25:730c:0:b0:b91:b64e:743d with SMTP id o12-20020a25730c000000b00b91b64e743dmr1199758ybc.9.1681494888506; Fri, 14 Apr 2023 10:54:48 -0700 (PDT) Date: Fri, 14 Apr 2023 10:54:44 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230414175444.1837474-1-surenb@google.com> Subject: [PATCH 1/1] mm: do not increment pgfault stats when page fault handler retries From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 87BC140014 X-Stat-Signature: mszt93zp4irui9yefusxon91mn48hfur X-HE-Tag: 1681494889-382072 X-HE-Meta: U2FsdGVkX1+/JS9uddBMm3LlsFvgQM+dKsG08zjQj7lYYRdr+/SagbyA0YuqLvY+own8zY2WAwpJ89qJvELpymFO2MIVPjcuInCnKwIr4QEDzHBO/8n6pXDGSawuzME5z0LwTQNX6AXx+rc1LdFFH80PfpGxtivzTU8Wd7Te0TWD+f5wEEhG8umuTkpU6eJmYa9HfKdgOemmD8UHVVCymh+j35PxtA7w7ZexrAnTGYYvVmOx75zNlb4eB0WSieGtWFNnukgQK6j+gbomARVMdtHPCDiDW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8N376Vfx+cCZHONKqY2UB6zDWgiUxyuAI05x2vFWEOVaE/4Zo9XRunQMwNCSauERr744GtOfD8T3u6Yoq7n7trbU79n6FgI5mzbODmciMgZ0uZ8wLAouLbewrPnda0dB6+mIOVEV3rkzlG38jZCwoesPtWuw4lyWWsL7KwOYM6SFfIE+wS+gP2+RZ8b0IUIGX8crxhqOf2vEov7LMlHvOtWJFtDwolQndBrXad9loGr+Ge6GuDUVvfKmUg3ZgbSnYtAySQXIOs3BUx6bNb5ZEXBAUYm/B26zgSsl5Z815AdMSUNKZpWyvM48dOtEjCtl3TgLllQ== 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: If the page fault handler requests a retry, we will count the fault multiple times. This is a relatively harmless problem as the retry paths are not often requested, and the only user-visible problem is that the fault counter will be slightly higher than it should be. Nevertheless, userspace only took one fault, and should not see the fact that the kernel had to retry the fault multiple times. Fixes: 6b4c9f446981 ("filemap: drop the mmap_sem for all blocking operations") Signed-off-by: Suren Baghdasaryan Reviewed-by: Matthew Wilcox (Oracle) --- Patch applies cleanly over linux-next and mm-unstable mm/memory.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1c5b231fe6e3..d88f370eacd1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5212,17 +5212,16 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, __set_current_state(TASK_RUNNING); - count_vm_event(PGFAULT); - count_memcg_event_mm(vma->vm_mm, PGFAULT); - ret = sanitize_fault_flags(vma, &flags); if (ret) - return ret; + goto out; if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE, flags & FAULT_FLAG_INSTRUCTION, - flags & FAULT_FLAG_REMOTE)) - return VM_FAULT_SIGSEGV; + flags & FAULT_FLAG_REMOTE)) { + ret = VM_FAULT_SIGSEGV; + goto out; + } /* * Enable the memcg OOM handling for faults triggered in user @@ -5253,6 +5252,11 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, } mm_account_fault(regs, address, flags, ret); +out: + if (!(ret & VM_FAULT_RETRY)) { + count_vm_event(PGFAULT); + count_memcg_event_mm(vma->vm_mm, PGFAULT); + } return ret; }