From patchwork Thu Feb 29 21:20:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13577659 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 3132EC48BF6 for ; Thu, 29 Feb 2024 21:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B62B86B008C; Thu, 29 Feb 2024 16:20:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B12E46B0093; Thu, 29 Feb 2024 16:20:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D9A26B0095; Thu, 29 Feb 2024 16:20:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8C7336B008C for ; Thu, 29 Feb 2024 16:20:45 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2E1FC1A1334 for ; Thu, 29 Feb 2024 21:20:45 +0000 (UTC) X-FDA: 81846110850.20.A1C7EE2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 4CCF8A0019 for ; Thu, 29 Feb 2024 21:20:43 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=huq3fmeQ; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709241643; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V871v9cpaT/ZiLQVfOfBMAPSUFcA86Nc3lP+LQjntow=; b=OkR0+LTx9fAcbSdbSP3QI5FhtZNzRP5clPOwrQOKEPIpH7mS+RHU9NXnSHViIjuuc8MBhL nVPsg/XLJSTsw2OEeOZIAG/S+GtMG55PjPLX7YktDEoS+gfO45HsAb1pV4e1WOG+RcbchU +DtN1izMc1e9M7DsMntLdy3p5s2Rux0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709241643; a=rsa-sha256; cv=none; b=Uxbir6hjCTR9VkggPvBIpB8InzgXRygoKnrK0zPm76/jlQEP5wkKb1CEWCw7njn1IwMg6w NdhX0kT9QLsNtil6BYQCns6QnD/7jUcoO+UcfqRDIBxvhb9M5J+soeNxkpIRCi+eeaESfV 1bTyp7jjDsY85qqWaz3/lBTuNFDHZuE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=huq3fmeQ; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=V871v9cpaT/ZiLQVfOfBMAPSUFcA86Nc3lP+LQjntow=; b=huq3fmeQGBhvDDIpssUY1ObY+y uZBiSjvEci25W+X7Z931HtrE1QepnbDXjHmrQ6y9wUpQIZp0/8JpAw1RfSJmilhIxqD93r9qnJENe egAvVUVJ5xYw/PjsYae7BqtVsJI2qir0TkkWdFNG4ZFb58Gf6nklvd8QtQ/uXPj6xAWLvqbHvS9AO uGF7zxU8HlWxxZSFLVoZ78R18gxFafFXlgTqJhO1ERnBAJFwRgrJzaUN6ePOlEnTuxZMlh5bEUz9k qXQRcOatQmLgYM0rsbeyN1tiCgr0vJi6QOrHWSgk9q/dzt8G1waWkdgFQ1/FiAIgeOUacol634U1U AlAYehaw==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfnpV-0000000949a-351I; Thu, 29 Feb 2024 21:20:37 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Miaohe Lin , Naoya Horiguchi Subject: [PATCH 3/8] mm: Return the address from page_mapped_in_vma() Date: Thu, 29 Feb 2024 21:20:29 +0000 Message-ID: <20240229212036.2160900-4-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229212036.2160900-1-willy@infradead.org> References: <20240229212036.2160900-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4CCF8A0019 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: g93dictsxa7gezioefzacbk7fkg8aknh X-HE-Tag: 1709241643-211965 X-HE-Meta: U2FsdGVkX1+YSIbHiDGNnkBR7NzDfjy7NLyoR4Ia5HfHhWhC8l6eOQPmch2SKtuXePPwPxR0pu+VXVry32BYwJM/EqQaVEEktWNyIl5P8F3OJDAr3cV5/NZhlceN7CcE7Zz5CyyiHsLbNc0e9di+57EamXzSqyf9lw9ltez5XNd2K7NCjkwcomz9g6tvyqTRSl3ldk2L7FsK3U8Fq5NFVl58ChtKLrLprQ3mUQF8Ynff1GcUSLMnNDC5x7pNihhqKjG3a1XEaU1GtMW3TKabpqtaFShCE3PJoaXX0bdZazvcDTWUGrIOG96LZx5l+ZjvlCUwEHzw+nxYhQt6bIuY6Q5t8P39Iv4xiY6H6OY17AeeGmtbPB7UkIdZhU2ndGeGEYPpY1bnS/hq/ukhxAiqfNbjea02l2P3Is85HPKrn1SyNicuGwjw30TntakaZQdicXn6kw4EPLSsPKVFYtdJyruiQLLGcFB2sLajOgEJYPlBC2A6fCLPLwDyC1yc/An50/I0MJ8VvJEnc2jFrMtSL4uSOs913Ns1PH8bwMCZhdSr5ZaYJo9I49eg9dCd4M9tYQK4XIIm+xkQ7rlqjpwWZKePy3l1MsRGh/vhJYFCJL9NJbtT5CYwStzgNHT38rKVo8vwHKiweofjZ6D+i4SsSiEIp2wx4fwM28AWX8PZJwFrEOqlBWAC8nzZwfi0pnE2MjbwFIpdecp5KiWf4/C0HlyIq4p7FpdIUuHpsK7405likJ/kt57AEwVvfBXt4nVZezezrfGu9HNwrFJ+0DiGcJnIe4RDMV7WG0yoVHNZKUD2fTpmVzkXuDezQl9Sc2gL1IL/Ja87lqolBQ7b/SM3pNlLfN2u4V9LZXqoIkpNNAXvaZO6pn3+K6q7ou/OdQ818FEHWu+i6sU4rxwa8R2g2PvaX+Jh62Qu 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: List-Subscribe: List-Unsubscribe: The only user of this function calls page_address_in_vma() immediately after page_mapped_in_vma() calculates it and uses it to return true/false. Return the address instead, allowing memory-failure to skip the call to page_address_in_vma(). Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Miaohe Lin --- include/linux/rmap.h | 2 +- mm/memory-failure.c | 22 ++++++++++++++-------- mm/page_vma_mapped.c | 14 +++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index b7944a833668..ba027a4d9abf 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -698,7 +698,7 @@ int pfn_mkclean_range(unsigned long pfn, unsigned long nr_pages, pgoff_t pgoff, void remove_migration_ptes(struct folio *src, struct folio *dst, bool locked); -int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma); +unsigned long page_mapped_in_vma(struct page *page, struct vm_area_struct *vma); /* * rmap_walk_control: To control rmap traversing for specific needs diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 7f8473c08ae3..40a8964954e5 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -462,10 +462,11 @@ static void __add_to_kill(struct task_struct *tsk, struct page *p, } static void add_to_kill_anon_file(struct task_struct *tsk, struct page *p, - struct vm_area_struct *vma, - struct list_head *to_kill) + struct vm_area_struct *vma, struct list_head *to_kill, + unsigned long addr) { - unsigned long addr = page_address_in_vma(p, vma); + if (addr == -EFAULT) + return; __add_to_kill(tsk, p, vma, to_kill, addr); } @@ -609,12 +610,13 @@ static void collect_procs_anon(struct folio *folio, struct page *page, continue; anon_vma_interval_tree_foreach(vmac, &av->rb_root, pgoff, pgoff) { + unsigned long addr; + vma = vmac->vma; if (vma->vm_mm != t->mm) continue; - if (!page_mapped_in_vma(page, vma)) - continue; - add_to_kill_anon_file(t, page, vma, to_kill); + addr = page_mapped_in_vma(page, vma); + add_to_kill_anon_file(t, page, vma, to_kill, addr); } } rcu_read_unlock(); @@ -642,6 +644,8 @@ static void collect_procs_file(struct folio *folio, struct page *page, continue; vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { + unsigned long addr; + /* * Send early kill signal to tasks where a vma covers * the page but the corrupted page is not necessarily @@ -649,8 +653,10 @@ static void collect_procs_file(struct folio *folio, struct page *page, * Assume applications who requested early kill want * to be informed of all such data corruptions. */ - if (vma->vm_mm == t->mm) - add_to_kill_anon_file(t, page, vma, to_kill); + if (vma->vm_mm != t->mm) + continue; + addr = page_address_in_vma(page, vma); + add_to_kill_anon_file(t, page, vma, to_kill, addr); } } rcu_read_unlock(); diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index 74d2de15fb5e..e9e208b4ac4b 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -319,11 +319,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) * @page: the page to test * @vma: the VMA to test * - * Returns 1 if the page is mapped into the page tables of the VMA, 0 - * if the page is not mapped into the page tables of this VMA. Only - * valid for normal file or anonymous VMAs. + * Return: If the page is mapped into the page tables of the VMA, the + * address that the page is mapped at. -EFAULT if the page is not mapped. + * Only valid for normal file or anonymous VMAs. */ -int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma) +unsigned long page_mapped_in_vma(struct page *page, struct vm_area_struct *vma) { struct page_vma_mapped_walk pvmw = { .pfn = page_to_pfn(page), @@ -334,9 +334,9 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma) pvmw.address = vma_address(page, vma); if (pvmw.address == -EFAULT) - return 0; + return -EFAULT; if (!page_vma_mapped_walk(&pvmw)) - return 0; + return -EFAULT; page_vma_mapped_walk_done(&pvmw); - return 1; + return pvmw.address; }