Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp426558rdb; Mon, 29 Jan 2024 06:39:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IERC72ck9YO3Z8j45u4izhWqT9XIS3uJOsY5dV6Ko0jJFzwzsHxZ9fWIfLMcmuXpWmBO/7E X-Received: by 2002:a17:902:ca03:b0:1d7:15f1:bf78 with SMTP id w3-20020a170902ca0300b001d715f1bf78mr4184237pld.42.1706539171117; Mon, 29 Jan 2024 06:39:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706539171; cv=pass; d=google.com; s=arc-20160816; b=AGvtIwqu9HUsg4WQW3npC3FYnJP+ekPfozFAMVbSyyb/jYLxgqTMVznlubF3QDWHwT T6A8bAUZhGX77U+M4nqbBFBOTzvGH/0/gEVYDSC8kzJ4zqclt/bdQHsZZw172Lw+tk2f Yv6MQ9/G7N2LB+jzDsm7q4bkSXFYRXwDzIcCMT0XXIgL5wQdH1z7S/hErJfylGt9VxKR hKTlB/uPUEwwfHc9e5w5fhllHlOkPdEFfpYqQxqOUvCy1s5P9dNEJtiHGNQsTCWkml8l Nfxm7U/esksEjKLlAqxHi5jKIZOzA7W/NBEMqv7z2orh50BkRG2g3QMCgoHZvxcRhCNp kbKQ== 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=L2zNeb5SO5KkYO9vfWjJtlZWbswbqsHyyrv464V13y4=; fh=18RVDvllJ6L23pprpg+CRg5YQHffBN1k78GW6gBbnXE=; b=nEvSpmiCxpeN90YFvpM4GKZ7CMZBzTvcDqjOGKVxSvlq9hEdoA91BUivnvV2JOCoMQ 5rA/5vyGQ/eB6YHXle9HLMYNwnofCre+nUl4VLp9QOJj9fZPZUCUSTB6i9zIJDmiLbHe SNkplS3prReuUW/chb4QKlPcnXM4mI94Pa0upWKQhXDS/JWDE04nUBVqdr4EwU/0qVjb vDstKpbrdhGCQQLIFcIqvVoy0+EkooUXq/1DpxoMdDJTO2Gqfy4+hjHsntQvdStavRcv 3P51u4BSpaGvwfIsN/+f7Z+d0gK74XNjhrw8OFgKb5/Jqzcy2fugvF43Y2C03znn5Aje LYfg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F2ORIhlg; 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-42914-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42914-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i19-20020a170902eb5300b001d8b8e1a685si541114pli.284.2024.01.29.06.39.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:39:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42914-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=F2ORIhlg; 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-42914-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42914-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 62643289EA9 for ; Mon, 29 Jan 2024 14:34:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A30BA153BE9; Mon, 29 Jan 2024 14:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="F2ORIhlg" 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 54276152E13 for ; Mon, 29 Jan 2024 14:32:55 +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=1706538776; cv=none; b=sAOJSfkvlVJC7VkxHlSXH27qIETKZspCju6Ip/47rM4HB3HYa1HceUAfUHw1xSCGiVQShiJVl1jIoqtVK6+HxgIxb9fHjs8HD+R+2E0NLJwh2FX3Ct0iQUYf8kMT4BwqflGeXmiRk2E5f6dltu/iy9pxgRDxsYBYWLBZ1yVdJ0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706538776; c=relaxed/simple; bh=XApK2c2vQna3bcs1NTRVr0RKnpu8isNDD00l9Yikal8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cuKgIyO86gdzRSr0V/Ki6inkAZHcWprp+yo+bzAHbftIJxoVp1KPaD1lzGFRiehCjtC6XQ4dY+2vf3TqqcMIp2n7ljaVe1IoI5eNb79+cVBzWLYQ4G5k+3MaPNciG2zNTKca6ilp4mW20rZo+n4MNih5sU/dC6j50/JQoC0lcys= 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=F2ORIhlg; 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=1706538774; 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=L2zNeb5SO5KkYO9vfWjJtlZWbswbqsHyyrv464V13y4=; b=F2ORIhlgST0Oaox48DuH6FpDMzyR8a3NNJlr3ncwGjQtwLgW0LYuQiXPJQ5raqaVTEK9ix 0fRq/3FNUJCLC092rYLQySYjiuB1oMwlQz7IZ4tXYK3HI0jP9UeTzqHMyLYr2+lkYsjxrC cAcx9xdg8NuvVKu6Y0JPHwcLUXRKbLM= 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-639-VwTjaewtMEGP-PpguyfRyw-1; Mon, 29 Jan 2024 09:32:48 -0500 X-MC-Unique: VwTjaewtMEGP-PpguyfRyw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 796401013767; Mon, 29 Jan 2024 14:32:47 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id D15AFAD1; Mon, 29 Jan 2024 14:32:42 +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 , 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 v1 4/9] mm/memory: factor out zapping folio pte into zap_present_folio_pte() Date: Mon, 29 Jan 2024 15:32:16 +0100 Message-ID: <20240129143221.263763-5-david@redhat.com> In-Reply-To: <20240129143221.263763-1-david@redhat.com> References: <20240129143221.263763-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.1 Let's prepare for further changes by factoring it out into a separate function. 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 20bc13ab8db2..a2190d7cfa74 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