Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp62663rdb; Wed, 14 Feb 2024 12:46:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/nu1QvhzZWMZ+TPMchuPtkyVr4XNInNIXKC0tWvaAGPsSudxvsKEXLGj4xkX6aM91V3Xef6BrowlD+B7WNyuieQAQhBxliNfj3zRD2g== X-Google-Smtp-Source: AGHT+IGgxEfORsfrkAjeeBWzdWRwS6wK7qgr2SEpvMsH5h1H9P7PNKTYbVp9ExK1gQEynsd9sSZb X-Received: by 2002:a05:6808:1a1a:b0:3c0:4038:6e8e with SMTP id bk26-20020a0568081a1a00b003c040386e8emr4429899oib.0.1707943591797; Wed, 14 Feb 2024 12:46:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707943591; cv=pass; d=google.com; s=arc-20160816; b=Jqx/HdOHtyZLHEpMXpqISJ+zhYFOBfei0vyNjlXvONHpxYHZN86gFLqGv+TEfJOqVR zEiGOPOxB1wdkVf+FnE9qU6RZyL241L7LEGG7YFraKVdfXp79aDR3b8Ta8q1a3vNMCuw ml/qSlYBKwe5qwDFanziPTuAKn5JXuJngCq4+NvcQIc/JKz7NJEEZ7t7cn1jEPkmYcgi 8054SK1kJFBZU6SMoe5A+14PQA3pmdMuK6MbZG0vEibOWQ+0qh+vByBzxK1LqKQ5odEQ rliyqNX1dGM0hRxHLz/+3y8BySkF0+s0tgKXqtUWqxHDADFCGA+TOEw32gpW1eKH2ipq sZrQ== 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=raGfvtIMV9OEXrDbDXvKfM+/BDhbo0a7ydyBOwqK9k4=; b=dtCyYKk8xUPvAPBiraoCsCZ7/03Lt2P66QscgltQlQOrMNGKrJDvV/WOGSo/W/ZF2b 23ICRiDhpGu7rzbFxHpaoEucVef+btdTLUvbxGTnRgMnp9lHynD3K9sfoqHK4ZOzsJ0D 4UwQ8K4pljXzyJaeGWa7nXy3jasNnoIC6LUHi421qeo5KvYUUjE1EoyffADjHYq6h9Kk CBqro3TCZ+qv1eUsl1G0/cO9TDA6vM01aiB2q4qNN3ol9OF1epbK342Dz/Yi11nYC2Ym /qQtI0fg7fIh4pHxbOCaworhYyyohUX951fpmhEBxhUnfeFfX1QAwwuLptY7y3huE1bA 9abA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QCbJHDSn; 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-65950-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65950-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; AJvYcCW4HWBuTPgx8dodQgI2rNFnJE/29PIh7fDr0MIzh/PtaWDQFxYHFyRaQVDqYI5dub4Ds6xpQNZB8Ll5HhLOWgEYut2dI0pr10Mb7KtPMA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y7-20020ac85247000000b0042c796ffe47si5915404qtn.486.2024.02.14.12.46.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 12:46:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65950-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QCbJHDSn; 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-65950-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65950-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D08751C2878D for ; Wed, 14 Feb 2024 20:45:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D842414199A; Wed, 14 Feb 2024 20:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QCbJHDSn" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 7D75C141991 for ; Wed, 14 Feb 2024 20:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707943504; cv=none; b=eQdEs5bUNnCo2F8724RM3n9+HPUg6KNHQTLYXI6zjOmKxsBOZ8uQS+/nAYp7mplI+42KIW3ba1b3JX9sGeU2EjB79rnmfyYFyup063PD42DYI+KfdzYW/bdhRPVUzEsv6ijMhEawV/G7D6L33c7UYr3S746jQKVavcz4GRL5qqU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707943504; c=relaxed/simple; bh=X688LQ+8vv1x+HYbDq06JeZc4jgkCPC+TN2xr2DyFa8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Id3ldX7IVE68BubyxAk1z6XFAvFSuQP01TlVWDQyACAakJGCK/G4YEsHufECcjZAz6kL6xZEjLw5rZgkFLFPdcmV7SPT8qkQfbR6aLYsCBJGGPWsHSvPb6IR/MCDdu4ST8Y9jXHdKVA4ObSurYHKdv2JXQE671zZdZtVCtKHOJk= 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=QCbJHDSn; arc=none smtp.client-ip=170.10.133.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=1707943501; 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=QCbJHDSnTubM8kNwtxKITUDly1CJsT2kTpkPEi5qJNh2YwoLkQ4axBRYx907HOnN3Rnyyi 83isEcpNaoznWLdxCFSr7oy6ywErQRIk+v6z/T+I2i75qpZ6RTEoM4yMatMdM0G638zvEC LdEr7jUOZgAYtyZnvGf3qseaGrW+8Yw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-cfALmccYMXOB9OP0YG_4hQ-1; Wed, 14 Feb 2024 15:44:58 -0500 X-MC-Unique: cfALmccYMXOB9OP0YG_4hQ-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 B0CEB10AFD6E; Wed, 14 Feb 2024 20:44:56 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.174]) by smtp.corp.redhat.com (Postfix) with ESMTP id 244661C066A9; Wed, 14 Feb 2024 20:44:53 +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 v3 04/10] mm/memory: factor out zapping folio pte into zap_present_folio_pte() Date: Wed, 14 Feb 2024 21:44:29 +0100 Message-ID: <20240214204435.167852-5-david@redhat.com> In-Reply-To: <20240214204435.167852-1-david@redhat.com> References: <20240214204435.167852-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