From patchwork Fri Apr 12 19:35:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13628287 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 82CC1C00A94 for ; Fri, 12 Apr 2024 19:35:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A57C6B0099; Fri, 12 Apr 2024 15:35:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 007F36B009A; Fri, 12 Apr 2024 15:35:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9A506B009B; Fri, 12 Apr 2024 15:35:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BB38D6B0099 for ; Fri, 12 Apr 2024 15:35:28 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7838780FF9 for ; Fri, 12 Apr 2024 19:35:28 +0000 (UTC) X-FDA: 82001883936.16.A74ABE3 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id BFD81100026 for ; Fri, 12 Apr 2024 19:35:26 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kaneDGkb; spf=none (imf05.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=1712950527; 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=K/R2o/PdWyzoA0RtTM1GHfRpuHZB2/ueGisS2u+9KKs=; b=O3pRWaf+jKpzZzaHWmBM5D2te0bk9WGdgNxtUltOBf8S5AwlR7egOgXoGeEuAG2BjAWlWX o+LjqxBgcBvczD1IX/8uoGFc4ks9AHCMsCZsNSiIiDjOxMPUq5DgPkdOciZE0Gn/S+p3AI S8aLOtjbrDCewDSsnQgIEE5w2mlJKwk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712950527; a=rsa-sha256; cv=none; b=P8nj/sCdjwPg0ws3/6duq5gNJWGw59AaA9pUOxzE5IBsvBWLJ/LMYWumyM/hJ/cfB2A3Z5 eoBME10skAa1YuIBn0Eliuk7Ca5+DoJiUGTevipBWL6dprmECSyBLwlbiTf65ocgGyC1oK 6J2/tm4le2euWT6tX1HvZCPJpGqCbI8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kaneDGkb; spf=none (imf05.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=K/R2o/PdWyzoA0RtTM1GHfRpuHZB2/ueGisS2u+9KKs=; b=kaneDGkbKKrpBXaqt0qM1rZmTr F0Tsbl+v3EmHU6ojlD9nXGSdGFdWDQ38ZgSVtq4X/pxsoZMDbfgkXqR8ifOyNmTFazlSvfc+Spc4i Le9qoaSEpv4JSzQ9P9OnwUGbTaIQY2oBWElaM6CTxhb0nLfOUXE59nHjHvyla4JUhpQf73aUrG0Fy Ld4DOqu1X6LNvOODxziA0b2jatqyRBAC5g81+jSo00SG9q9D8WPP+rCTludKXnnmCM1HPNKA0rjrp tBkkX5P85Cx3BJb/DLOkbnCnzM+TTTMGdsAafmtC+aVRP1UeGtY2ynirlyQgyWDxYIkXU7xt8EgBu LriXXy0Q==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvMg3-00000009t9i-386h; Fri, 12 Apr 2024 19:35:11 +0000 From: "Matthew Wilcox (Oracle)" To: Miaohe Lin Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Jane Chu Subject: [PATCH v3 03/11] mm: Return the address from page_mapped_in_vma() Date: Fri, 12 Apr 2024 20:35:00 +0100 Message-ID: <20240412193510.2356957-4-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412193510.2356957-1-willy@infradead.org> References: <20240412193510.2356957-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: BFD81100026 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7g5pgecufyeseozaefwaxcnugehgo877 X-HE-Tag: 1712950526-262765 X-HE-Meta: U2FsdGVkX1+Kw8p9B9lLruzMp70Il3Z+GTiU8BKLBEhldVyz3PMva6Nm8wOzy11rpdSRa33VGfk225fimFFJGZ9ZZPQSKha20/Razh6MyGpSkhLqNDtSZRFROACxPU9HO+uSCUeMWJ4aaDHtIU5BbLECoNyQ1wV+8h42J7flg/ZvaV+czkadYYoAO3Q/cVTn0GNUB8LdpfofnDedX63r9UCcTr+tVFc+POlZPyOFiD/6xrdx41HwmZ3JpRsD1HKuVYnC+4bhNNqsafMXz2qDiZZgGbPyKwZMQGV1tGuuR+MXsi/YRpSHqcm5J90VY1ZW4u6d0JEGCmb6Hcg+Gytrd9zxMUmvzoxq1zg165V0JIpInNoEecy/H9tqqf5N/rP9pY1AURPmCe5C9sEsaqlvP0my3pn2ZverZvBHuKFzytcCGcFu4LwD62KRKwWlsv25Ejfk3LDhLKTj7NKrcVZ8/UZvB5bRI19T0quNW18FblnYNZJYjqdjWdWY8FhLqL5z/4vp32o1W6sqvVnaOoLAoy0dPPzFrixryNqKdrm+F0EE1sp/kz4U5ktOVWizeAsrcp8+KZgknia+pyrsA/D1NYXM728pqnOSDeuqcruVyiphmH6AWUxYiriGfO3uktCLG7ncd7ihirRJsfECyUhMnWBzWj5HXGkkF7MZSh3QzosahQDtG5qFkMVqa8OfGVfjQ8eE9MGfyOoTkU+Q4mQM6r445U3PGoOpT6oPv6UcdWheey1hlhzLjc1ESUAKZdkBIlr5BeVTRbFLQ0PTWkIPXgBZMIosfoDOcaioXDB18n3H6LzEyHLA/yEX8adjiwjnQvdn94xkGTyt5KQrIzjS0M+VpNFmHjiZyFwtUqHTitffUVzJKAp7Bh0nWqE9R21gVltaIFe4IA+dZUFF6oiyCWK5tcOx/nrEpb0J5z//QGg= 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(). Acked-by: Miaohe Lin Reviewed-by: Jane Chu Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/rmap.h | 2 +- mm/memory-failure.c | 22 +++++++++++++--------- mm/page_vma_mapped.c | 16 +++++++++------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 0f906dc6d280..7229b9baf20d 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -730,7 +730,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 aec407788df1..0ad6b8936512 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -467,10 +467,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); } @@ -595,7 +596,6 @@ struct task_struct *task_early_kill(struct task_struct *tsk, int force_early) static void collect_procs_anon(struct folio *folio, struct page *page, struct list_head *to_kill, int force_early) { - struct vm_area_struct *vma; struct task_struct *tsk; struct anon_vma *av; pgoff_t pgoff; @@ -607,8 +607,10 @@ static void collect_procs_anon(struct folio *folio, struct page *page, pgoff = page_to_pgoff(page); rcu_read_lock(); for_each_process(tsk) { + struct vm_area_struct *vma; struct anon_vma_chain *vmac; struct task_struct *t = task_early_kill(tsk, force_early); + unsigned long addr; if (!t) continue; @@ -617,9 +619,8 @@ static void collect_procs_anon(struct folio *folio, struct page *page, 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 +643,7 @@ static void collect_procs_file(struct folio *folio, struct page *page, pgoff = page_to_pgoff(page); for_each_process(tsk) { struct task_struct *t = task_early_kill(tsk, force_early); + unsigned long addr; if (!t) continue; @@ -654,8 +656,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 53b8868ede61..c202eab84936 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -319,11 +319,12 @@ 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: The address the page is mapped at if the page is in the range + * covered by the VMA and present in the page table. If the page is + * outside the VMA or not present, returns -EFAULT. + * 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 folio *folio = page_folio(page); pgoff_t pgoff = folio->index + folio_page_idx(folio, page); @@ -336,9 +337,10 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma) pvmw.address = vma_address(vma, pgoff, 1); if (pvmw.address == -EFAULT) - return 0; + goto out; if (!page_vma_mapped_walk(&pvmw)) - return 0; + return -EFAULT; page_vma_mapped_walk_done(&pvmw); - return 1; +out: + return pvmw.address; }