From patchwork Mon Jan 22 19:41:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13526142 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 EA064C47DAF for ; Mon, 22 Jan 2024 19:43:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E6CC6B007E; Mon, 22 Jan 2024 14:43:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7976B8D000D; Mon, 22 Jan 2024 14:43:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 638598D0001; Mon, 22 Jan 2024 14:43:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4FF286B007E for ; Mon, 22 Jan 2024 14:43:15 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2BF59A0684 for ; Mon, 22 Jan 2024 19:43:15 +0000 (UTC) X-FDA: 81707970750.21.A7933F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id A219AC0017 for ; Mon, 22 Jan 2024 19:43:13 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iB5TJCMr; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705952593; 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=OpHohfrBZPpQ+Ag8soc6zzIQIq/5TLvJxKBi0yYAutY=; b=I770wBoDY8jLKb8p0Dcg7Yg3QRwyygca8oZBjXU5aSvzV7wiQHgUSsDZFWLxeNXVyqYI6o x3tf+L6BU97bJwk3kGJY7I5Non/Mx1CszWKdPul6vHKdiKZmMQL2fw+em2yWN2I+X85AM3 VVUJRn7psMFmnBVn1odeLhZCDfQ11Y0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705952593; a=rsa-sha256; cv=none; b=tc2Hz+sussc57pB4oH2aJfeyP49hOuO5+yqsFNkm7gwLKSj9ep5pTm1fPaJhwI6QIEodfg XSdEQobMkNfKCPLgNex7VLBGaOuhuYP740DoVXKaOjqE0FWeZABInp08ON/J2JnQ7IdNo7 nf+x8sB6JyfxhzkY9NOlxuUyVShOpPs= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iB5TJCMr; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705952593; 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=OpHohfrBZPpQ+Ag8soc6zzIQIq/5TLvJxKBi0yYAutY=; b=iB5TJCMruJyOUVEIUpxlfDQIgb9LypypkStctisTPuRNxG2RQOMmRPaBNdUtCeASJZyPen W40mRoQTTW8N5hgREGsWlDVWWpL3z0ICYbFMWsx8Hmw3/FCM4cHXgwqVbgds2lfvhN5dif GZtg4pfY7o53gHkbXLRAb6svCv7xRs0= 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-499-dgbcNuPJMAq9R1a_XNgOmg-1; Mon, 22 Jan 2024 14:43:10 -0500 X-MC-Unique: dgbcNuPJMAq9R1a_XNgOmg-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 AB3D888D145; Mon, 22 Jan 2024 19:43:08 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 851B33C2E; Mon, 22 Jan 2024 19:42:58 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Ryan Roberts , Russell King , Catalin Marinas , Will Deacon , Dinh Nguyen , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , "David S. Miller" , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org Subject: [PATCH v1 10/11] mm/memory: ignore dirty/accessed/soft-dirty bits in folio_pte_batch() Date: Mon, 22 Jan 2024 20:41:59 +0100 Message-ID: <20240122194200.381241-11-david@redhat.com> In-Reply-To: <20240122194200.381241-1-david@redhat.com> References: <20240122194200.381241-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Stat-Signature: 8b9n7sxycxyz1mpc9ixwha3s45u8jsrw X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A219AC0017 X-Rspam-User: X-HE-Tag: 1705952593-61231 X-HE-Meta: U2FsdGVkX1+r6w7N8rkxavRMQryafWW+fPtqNjiJgHxTdWC4cKk1dItIt73xDJ0js7IwEffy/6yPzXDOt7mWgdwrpWM/bkAv8XbKcTVWoHp4vHkTG2IbSGCMSnoOMGr+urxKcwMFlugm+F38RwKB57eBq4CwXXahCcQGbkn2jWfCiND3+RLMsl/fvHUs2DtaKhIERPHH56D1/hENkPwGTfc2ssuOahbnMed05ZYtLcC5E8BJ/hHPqMtH9WjxXAjI35Gl1XRt8S56lzzB1hDOUpWRaRBLmFLOWarRwrvKf9AWqCfFQofqEGWwJ2Ol1iZVvinXg5Ge0gi9SY9Vt98k8MDp9QxwiViO4AHuZIrwBAys/IEQcjeh3wXB6rSSNHOJFhFiWqFt18sdh/PP6BOPYAA8BdrbEdXYFoAch8uIXs9CGWwdF4r7f5TjmhRWYgKhFT8jGC4ow3/LGJe0dPYozeAo4njLagTHuFcz8r7TIyPDwuYqMi9RyzQeEjaWjd2CkxzyRYgDboFOzq+ssCcCq8f0DtvkEEhQMheQNqXPztrjZ4nSMD3lefKzjA4Cz63XFqG7ImCxy3mR/QcRVFyP3aEC2I5rH6QuBn8FnJ4uVUAATFul9uEVMa1eHjYXH1No65lCai+kiuFhG239fkAEPPADUUfRK+MfCDC0BPbJhvZV/JZrtD7XfZvq7fSHvpriP6TkYjIpSo0+U4AGFlHLxeIO7qneq2Y06XU2ybb6vc6LpZbzb9R3OERu5LixE5gp111S2PpbtjA/WA+jhRNQHheRbVROiA7wDoqhOVmDLKcrfmoWBaNvwPI9dRTRjv1/D+6tcQKh4dDYI5XgVe/FjMWLoSMSs8wU4UUs9GAcz1MN2l7CMh69dMLMi2NnpZJxAsYyuNC8Kl//cb/ayy+YjxGap/jqlOnpS/fDXY1uEtstK4agJXEhbAvMowCWEvxD 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: Let's ignore these bits: they are irrelevant for fork, and will likely be irrelevant for upcoming users such as page unmapping. Signed-off-by: David Hildenbrand Signed-off-by: David Hildenbrand --- mm/memory.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index f563aec85b2a8..341b2be845b6e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -953,24 +953,30 @@ static __always_inline void __copy_present_ptes(struct vm_area_struct *dst_vma, set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr); } +static inline pte_t __pte_batch_clear_ignored(pte_t pte) +{ + return pte_clear_soft_dirty(pte_mkclean(pte_mkold(pte))); +} + /* * Detect a PTE batch: consecutive (present) PTEs that map consecutive * pages of the same folio. * * All PTEs inside a PTE batch have the same PTE bits set, excluding the PFN. + * the accessed bit, dirty bit and soft-dirty bit. */ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, pte_t *start_ptep, pte_t pte, int max_nr) { unsigned long folio_end_pfn = folio_pfn(folio) + folio_nr_pages(folio); const pte_t *end_ptep = start_ptep + max_nr; - pte_t expected_pte = pte_next_pfn(pte); + pte_t expected_pte = __pte_batch_clear_ignored(pte_next_pfn(pte)); pte_t *ptep = start_ptep + 1; VM_WARN_ON_FOLIO(!pte_present(pte), folio); while (ptep != end_ptep) { - pte = ptep_get(ptep); + pte = __pte_batch_clear_ignored(ptep_get(ptep)); if (!pte_same(pte, expected_pte)) break;