Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1217465rdb; Fri, 9 Feb 2024 14:17:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8Cian+e9vbu5gIZzB6MNC9XVMF4e8EuVvsfayBJcyGR1jnHoKyJefRQ2i47crfgBs92vR X-Received: by 2002:a17:902:654d:b0:1d9:87b6:e098 with SMTP id d13-20020a170902654d00b001d987b6e098mr606870pln.56.1707517026085; Fri, 09 Feb 2024 14:17:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707517026; cv=pass; d=google.com; s=arc-20160816; b=V6T+g+9mDG3QyywvYh9iEiKVo8J3QNr3QCGh2Y7ftl9SDJB1xPf5A6NO2XK0Qhb5ud fQKbZ5RSbmBaXb2jzgXlz19p+hr8AiMspOOGzHimZ8HkVbEMjSTBN9rcZUG72USr/e5h l/MK1c908y9ggYUXJ6hzVIjvXsgPPNj4z9wgZPiEioH6rLCTNix3NPBCZY8oiv8flpp8 HHLxQX04NXlBxKWVwjWuoQEKjFOdsw4tXBAV/oyON3RySOP4gRt6lw65vP8B2honZUVx KwCz9I3GzeLdhenUEM+RJ7D3TcurLBNzJZ1OVYFxKnhjXRV+YKrf/q5ddjqla42aK0Au r7Rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SyWghWuBP6GkqnhxcyLXYq2ssX4b7HML4Pf9katCZ5k=; fh=EFAsvFd/rLevxIWNBeGWtyf7FwbeAUjyBC4s8mXSIQ0=; b=yx6eS7vseTCBs9RKCoF9HWeAptjVZaQiJwb7R1gJaUsMdL3D9t0Ih3Qwkl0QMpbPRI IIbd5xw7zT1247fVQGf4YWj7lGfwbIVgyMAMqYuZn5t1B+dgEHg9fa8pHAmOjUOtSUiI Z7qPeEZisxepFNGLG18kkvoaC5GkDFjrj4JKHUbX+rzTa2whzdzSUc7+rSB4s1DajsxT wQ2Pi4A7pY9uVWHgDlFgmUCFOzLsINrajWLEZpe6/82KZqobkS/lFeQYVCRS+BC06cUg Ra4EcY7tW2CEs0MYdCigwsWR3pvH4OoATl8HDbhUVT/CzZp0BsPEjV8ZQ8BOj9v5NTTm YA2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Nuog7vqS; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-60076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60076-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCUQ719606pS8Mw0mmt7Y721dJ+Xo2sijNc1U2kozRc5kalJ7W4Lw479KXZCKQhSAbuM7JodL/x77SzHeJseEVymOAYb7BSdBFULNAYnWA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u13-20020a170902e80d00b001d969a78d7bsi2457793plg.54.2024.02.09.14.17.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:17:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Nuog7vqS; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-60076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60076-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9EC402856DB for ; Fri, 9 Feb 2024 22:16:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14EEC36120; Fri, 9 Feb 2024 22:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Nuog7vqS" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89B8633CD5 for ; Fri, 9 Feb 2024 22:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707516947; cv=none; b=hrjOZkPz34sjgmisnFCWPH2sn74W1XnIzYb6AEiPYKS1083XnvCAMiQFEvDomXshT+QTvZlX1MdtNH6Z8Ilubkzm2wcNKkBf6O/q3NnMA1B4GgmjgJ5HoQ3m1ATjtGiOuaYYaQRfagIesHmumftstbspXu4gzqR6G152WMmdCFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707516947; c=relaxed/simple; bh=X688LQ+8vv1x+HYbDq06JeZc4jgkCPC+TN2xr2DyFa8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FPMpkbeW52yC4rhv+sNd0aPrWrv9Lmza7dgn5nX1QrMG3g7l6IPyqVJ4aACd0+ctskv7Qh3X2BhEpyF46Nbhy0Y+vpJGowSFR2lOosxo8mw2kVXUMuyR0cgOKey77Oxrcp/VuQzx00L73j2Dj6XCzidJkr5M5DTRmZGpPOjhY+8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Nuog7vqS; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707516944; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SyWghWuBP6GkqnhxcyLXYq2ssX4b7HML4Pf9katCZ5k=; b=Nuog7vqSEHMKunx6ebi6mA/fs8mk32+yst6bx6FGWBgDx8dkS/MPWE5NBogsU9RsFMK7nl 554AWkyLBKp3A1/O9s/1a04d/l41S6fzvmYJkvE4xQupnZFR5w5izc0nlZbKFnR7JEpUGt gIj8/HRkcam/JB5RtFIOkIbn48u1L4E= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-umYgGBJnMqW48D3blg8DZg-1; Fri, 09 Feb 2024 17:15:38 -0500 X-MC-Unique: umYgGBJnMqW48D3blg8DZg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED4963812023; Fri, 9 Feb 2024 22:15:36 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.194.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id E569E1C14B04; Fri, 9 Feb 2024 22:15:31 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Ryan Roberts , Catalin Marinas , Yin Fengwei , Michal Hocko , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Michael Ellerman , Christophe Leroy , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org Subject: [PATCH v2 04/10] mm/memory: factor out zapping folio pte into zap_present_folio_pte() Date: Fri, 9 Feb 2024 23:15:03 +0100 Message-ID: <20240209221509.585251-5-david@redhat.com> In-Reply-To: <20240209221509.585251-1-david@redhat.com> References: <20240209221509.585251-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Let's prepare for further changes by factoring it out into a separate function. Reviewed-by: Ryan Roberts Signed-off-by: David Hildenbrand --- mm/memory.c | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7a3ebb6e5909..a3efc4da258a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1528,30 +1528,14 @@ zap_install_uffd_wp_if_needed(struct vm_area_struct *vma, pte_install_uffd_wp_if_needed(vma, addr, pte, pteval); } -static inline void zap_present_pte(struct mmu_gather *tlb, - struct vm_area_struct *vma, pte_t *pte, pte_t ptent, - unsigned long addr, struct zap_details *details, - int *rss, bool *force_flush, bool *force_break) +static inline void zap_present_folio_pte(struct mmu_gather *tlb, + struct vm_area_struct *vma, struct folio *folio, + struct page *page, pte_t *pte, pte_t ptent, unsigned long addr, + struct zap_details *details, int *rss, bool *force_flush, + bool *force_break) { struct mm_struct *mm = tlb->mm; bool delay_rmap = false; - struct folio *folio; - struct page *page; - - page = vm_normal_page(vma, addr, ptent); - if (!page) { - /* We don't need up-to-date accessed/dirty bits. */ - ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); - arch_check_zapped_pte(vma, ptent); - tlb_remove_tlb_entry(tlb, pte, addr); - VM_WARN_ON_ONCE(userfaultfd_wp(vma)); - ksm_might_unmap_zero_page(mm, ptent); - return; - } - - folio = page_folio(page); - if (unlikely(!should_zap_folio(details, folio))) - return; if (!folio_test_anon(folio)) { ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); @@ -1586,6 +1570,33 @@ static inline void zap_present_pte(struct mmu_gather *tlb, } } +static inline void zap_present_pte(struct mmu_gather *tlb, + struct vm_area_struct *vma, pte_t *pte, pte_t ptent, + unsigned long addr, struct zap_details *details, + int *rss, bool *force_flush, bool *force_break) +{ + struct mm_struct *mm = tlb->mm; + struct folio *folio; + struct page *page; + + page = vm_normal_page(vma, addr, ptent); + if (!page) { + /* We don't need up-to-date accessed/dirty bits. */ + ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); + arch_check_zapped_pte(vma, ptent); + tlb_remove_tlb_entry(tlb, pte, addr); + VM_WARN_ON_ONCE(userfaultfd_wp(vma)); + ksm_might_unmap_zero_page(mm, ptent); + return; + } + + folio = page_folio(page); + if (unlikely(!should_zap_folio(details, folio))) + return; + zap_present_folio_pte(tlb, vma, folio, page, pte, ptent, addr, details, + rss, force_flush, force_break); +} + static unsigned long zap_pte_range(struct mmu_gather *tlb, struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, unsigned long end, -- 2.43.0