From patchwork Wed Nov 8 18:28:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13450385 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 06587C4332F for ; Wed, 8 Nov 2023 18:28:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 902B78D00C5; Wed, 8 Nov 2023 13:28:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B27E8D00C3; Wed, 8 Nov 2023 13:28:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77A748D00C5; Wed, 8 Nov 2023 13:28:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6A35E8D00C3 for ; Wed, 8 Nov 2023 13:28:28 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2243716024D for ; Wed, 8 Nov 2023 18:28:28 +0000 (UTC) X-FDA: 81435622296.19.69BE9AD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 7E505120011 for ; Wed, 8 Nov 2023 18:28:26 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=vbaruzZi; spf=none (imf29.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=1699468106; 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=Hh7iR22H/bMBGg1WTep51qz0ES5l/FVjx1m1RYU2PfQ=; b=wI80cmjYAGCpLzNdHSbVak/dSOdKRjOSI0IX4eKUlcCwYJnAGs6ZIX1pOtbpHLKEGG+JUB e4qsTKxNq9/siY3P39+99Bkm1MFU4tFZU7pLCV4D+toEmdf+V3Q9B9KtCIs7mbPmKuWjTK s4AGHmxeWaYHVDWoiJTsz3qunFI2Vns= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699468106; a=rsa-sha256; cv=none; b=P0HPMYv9BjPB/1TzIv5ynQdN+JYbei18s1GCty/vWBsXx6uGRvhpIUdegFpU7ohk7usP1e Z6s6tHvmvKuMCg2JVGwEt/poSNa6v7nurMBdYA7tty/Qx59lm4CdE0xXQys7uqFhI+GfGx ttLijerSNrvkMOsbx8eFE8hgiTjfHfk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=vbaruzZi; spf=none (imf29.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=Hh7iR22H/bMBGg1WTep51qz0ES5l/FVjx1m1RYU2PfQ=; b=vbaruzZi/nRV0eD5bIifbhL48M lrsEFUNwWq7APBHxiX/omLWGhaMszAff2PpF8eYHbnXmrIvbDx1WWo5yq0yCn6qTLK0Utd+fLTWax a5Y7SkOOj83Jpdw2Ndn7xGpTVs5z+KNqqpjHV9bChnAavQP9fL/xf9DdIjgWfcgT00+LpWfkImjz1 C8jiymDHrQ8luWORDfZL9iisCP3FUwGIeXWi0kJNQjzYEOJ700dDpPNmS+53X/yfm9GfNxM+u1ZeN 8vWwmtyUZll+1thVFzvLzBLj7V1bUQtxdpECKQfXJI4VztC/c87t1OGEctUFM/Z4cNQkhCizbO1Ot ImvwbaxQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1r0nHf-002WdI-1E; Wed, 08 Nov 2023 18:28:11 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , Naoya Horiguchi , linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH 2/6] mm: Convert __do_fault() to use a folio Date: Wed, 8 Nov 2023 18:28:05 +0000 Message-Id: <20231108182809.602073-3-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231108182809.602073-1-willy@infradead.org> References: <20231108182809.602073-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7E505120011 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: iydxk91yc4p6s5awqehm6gi5xgr6k6kb X-HE-Tag: 1699468106-792278 X-HE-Meta: U2FsdGVkX19mRkplHPYEIJkOsO6qAlFRtG4ZrYZ0DuPQ7LZ0lsX1n75mqbhqeMw1rrIe6lqFvS6OD/lE/b5qjRWamsYDXD+PkYlxF0uT+9c+/95m/+tnoIgdLINdaEyjmE1LdLKl/dRlbiqem3WQwf7Gca6UiyQSfcHIkDHOtLGq26t7lCmfiG46zSGLCX8AUiSKWiTPI8xY2SvJxrnEkHDGvAQBp7HVtg4tn2HYBBU3obauVh3Efu1sF1hww+5Po5SkP0cFrnpQaoCgxMTgTZKB/m7LvvvZlbKqSomNt1/+n/CjljjrvKZC3pe106XxNha/HvldAMBwUml0Cojv71yJQiu880k3ulSlBYykKKgzw8R4DHBYED1CxCSmA9fO54Y/N7MYA2Bk39ovQiHbHGgX8/TZZrd3cpdnJyjppnmWVSwom0F1RAt/jbmoiCy1taIeqH08ofYZeDln7h7TJH6d90WNL/fyCaYPvyzx+8Z5ZE75FvyxCw4qvAcjBZ4FVCmnTmkEppYUushAG5MX2jb5kQ2+E2u9htGKkwxsFjZ7vcSG4yRWmMgkrWQzUJW/ZD9r4e+/aF8r1udEs4Qp8z/EAj75yi1UZqtAKTGwtS+RX9fKsYjR4RBFF+0ryfvpHwyhkEACn7DR/874jysNCI0ks3nVP9wakolOmOuJa91hEmaHlX4ZyBPG7x9R03Ix1Dg94wUFcH4ES59PIR6uOpmo0ha12izKvZWw/g1YfLt9gYukb0ap5NXtsVLJYbzufik0XDGU0ru75c/NkEjBGKOuACrofZQZ/xEKNpmNnhHkLDtlWWm0hJRCPo3w1EFyzjd4P6URSOyhn8BUDvkd985cY4t1AEwbXiiCa0r3ACKPJcoh+oMFVXafjTKXyZ5N9PXDBvzvVDBKrEWaOwZLixA1uJ5x6Tekuxfx8K8lc9bfjg5xJR+/mZx02i5Eg9jV7mz0zXbMbA1J42w+U76 7IO7Z5vD mcRzdUIdv21JYc7vCcktsy+lK8vNoLhvukSbrppZDjHGFgAZeub03M1lu8Ow9eO9+diiLWU1ulIEBr4Z9lqo4PVLLeyjmLB6L9IHBZ+AXEU37jh3aC8nZ2ViViuTLVQhKWcHD+rHtek/58c+oOYwvp169D0VB+Ck0JN6worUHkQDfH+Hmkv9Mjg/5riqboYNvzE1h2OZySA8cIg1u4aDgUY75YVvaTN9VXyzcadbT37i5RatLBGvMiaA9rtX5+K1lqGcsTByMlFNfTS5heV016hBHyUX4Wd2A/LXl 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: Convert vmf->page to a folio as soon as we're going to use it. This fixes a bug if the fault handler returns a tail page with hardware poison; tail pages have an invalid page->index, so we would fail to unmap the page from the page tables. We actually have to unmap the entire folio (or mapping_evict_folio() will fail), so use unmap_mapping_folio() instead. This also saves various calls to compound_head() hidden in lock_page(), put_page(), etc. Signed-off-by: Matthew Wilcox (Oracle) Fixes: 793917d997df ("mm/readahead: Add large folio readahead") Cc: stable@vger.kernel.org --- mm/memory.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1f18ed4a5497..c2ee303ba6b3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4239,6 +4239,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) static vm_fault_t __do_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct folio *folio; vm_fault_t ret; /* @@ -4267,27 +4268,26 @@ static vm_fault_t __do_fault(struct vm_fault *vmf) VM_FAULT_DONE_COW))) return ret; + folio = page_folio(vmf->page); if (unlikely(PageHWPoison(vmf->page))) { - struct page *page = vmf->page; vm_fault_t poisonret = VM_FAULT_HWPOISON; if (ret & VM_FAULT_LOCKED) { - if (page_mapped(page)) - unmap_mapping_pages(page_mapping(page), - page->index, 1, false); - /* Retry if a clean page was removed from the cache. */ - if (invalidate_inode_page(page)) + if (page_mapped(vmf->page)) + unmap_mapping_folio(folio); + /* Retry if a clean folio was removed from the cache. */ + if (mapping_evict_folio(folio->mapping, folio)) poisonret = VM_FAULT_NOPAGE; - unlock_page(page); + folio_unlock(folio); } - put_page(page); + folio_put(folio); vmf->page = NULL; return poisonret; } if (unlikely(!(ret & VM_FAULT_LOCKED))) - lock_page(vmf->page); + folio_lock(folio); else - VM_BUG_ON_PAGE(!PageLocked(vmf->page), vmf->page); + VM_BUG_ON_PAGE(!folio_test_locked(folio), vmf->page); return ret; }