Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2431994rdf; Mon, 6 Nov 2023 14:10:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFs+fgE165AQGNHf5AvgdIFdgqIyg3YgJDqwdVFAjWuVL4uOIxc4Mt6tLsbsYEtdQnb59FY X-Received: by 2002:a05:6a00:3a21:b0:6c3:41d3:9630 with SMTP id fj33-20020a056a003a2100b006c341d39630mr14792144pfb.28.1699308640102; Mon, 06 Nov 2023 14:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699308640; cv=none; d=google.com; s=arc-20160816; b=XY9EBFGQputAtuLnsAuZv7pXFrBlZKyKaU2vyqhfm6xm/xYYnWFiJLl9Cnf6HfKIvg TR3sQctdQX4MgMTzzbCuNIfMOW39H3LUfWkPXuVABNNamB7CGWe6AcRyWSpMsqtCrXgy weokkvP9qTxwrZz0PsKzfBHE6DaUqHbabiUU8FngFuUCL/2Y6ol53RGnRonDztkSbAU3 DkeeL6MwpJqRWhwNeQpsYdCWPzQEWeG14syUoBuigJsitXwUA15Zw6EJBH0Aqz+X6dsC gm/cw249TWeviJgoV8D4QIp79KiSKZtZ1RvQolOF3zWu4X4O75YD127aZW+Cr2VV5o4G BZ2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:mime-version:date:dkim-signature; bh=ndxuLkPMKyChC51AXz0puMMS4+/C4wl7scpf4W3agH4=; fh=r8pIO74m6RxQcs0DUwEWeArobKUZTA6j0g/QJOb1cS8=; b=GLv+696dfDWwkprbz2bQ1tIhRnnU7JvDbp/diSma2U90l5xY3n2k+kof1nczN+mZ55 EoqnDK7/l9s9KvhO/ebUukIO2i7p+pTSMJF1E6lnM/wCFBDh+W2CZDyWZeSQV9WjWhTb Gtdp5M+08H6k4yxocBCHKcFIeubSvQfzA4ZXY9lxH2FTSvDi4+EG2zR4bAyGOueKs/MY hA5ugjOXLoAoDLsSIVXhevso/eBk1dE9kNh7l4lMQxMF062xtYPU4C3H294m9QxKNJVM mRB+PWs8l5cZBCVcnKdd/eC5tr93YwSAlfYziEGTz26vmg9pg2GBj4JQ2NctSt+3HXl1 o5/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jtq2pPwv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s22-20020a63e816000000b005b99683f21fsi588370pgh.760.2023.11.06.14.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 14:10:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jtq2pPwv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 971D88062BBA; Mon, 6 Nov 2023 14:10:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233258AbjKFWKJ (ORCPT + 99 others); Mon, 6 Nov 2023 17:10:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233247AbjKFWKI (ORCPT ); Mon, 6 Nov 2023 17:10:08 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A8DFD47 for ; Mon, 6 Nov 2023 14:10:04 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9ce4e0e2bdso2870386276.3 for ; Mon, 06 Nov 2023 14:10:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699308603; x=1699913403; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=ndxuLkPMKyChC51AXz0puMMS4+/C4wl7scpf4W3agH4=; b=Jtq2pPwva/fCp5CQxd3z1o/8kv1Ct0fONL9f1YDDuruSBqudt25s3yGJFSTrPnPup5 zTCQSKa1cemDRfykU5nmYPFnGuRWV4iaDfM/oPf7wnBqPHjvo4/ZseQkPhUPFBeR0rC4 WOdY7vjGDWFlu5B1SafaEevz175jTLKUJlUHyKahKxymK3A+lmh/SYjTSkhdrITTp6WS /N+kh4HSwws1Mf5secjkk5uR2880jbXou5XO5Hpg/Z9zSKtClr8xXNF20D6DKVOTvJHE wq/MLqG3LprcS81QlAGv+IQY8R14BuW5K+VJXN4E5VZjgELuIf2eb1radHhd83FL2K9O TD+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699308603; x=1699913403; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ndxuLkPMKyChC51AXz0puMMS4+/C4wl7scpf4W3agH4=; b=SGyOsBMCtIkrzeC0xoI7TryezAw95Hoe/wt2kNQYw+xIiMRhUXCWBeL8/p1U/bFGRL JU1ON1pvMaZ68X9Wim10EpfBTr3wZ6NuyOX7Sg5M1PNz4QA8TVAGuxT6YoouoEmeecWq WbhnVbK5ZF+kCLyYNpt2BcDvT14GylNqcuKXnGXvoXG/MIEKr3IJfSGNL/RgfTIBn7F5 kFGl/WzArp8VIxn0dWlZGJxeXw5Phq2u3Wlf0OMSVWWv0xc1qSMxpklGI9YECbhvlntd 7VchXj0q52AS4ty+TX4H2FPosc2j1QFN8CMeE0PX4VE/oixBfsnZd7wdci1aF38BiewK aoEg== X-Gm-Message-State: AOJu0Yx0Ft0X9JZ9pKIYwpN/n/Gl2rsnXGtvGoSGeSIOqwePoK89NU2D kfBPifStP8lJKq7KkwEhGQFcPDO7ybo= X-Received: from avagin.kir.corp.google.com ([2620:0:1008:10:b187:459d:af36:db4c]) (user=avagin job=sendgmr) by 2002:a25:ce94:0:b0:da0:3bea:cdc7 with SMTP id x142-20020a25ce94000000b00da03beacdc7mr546295ybe.2.1699308603190; Mon, 06 Nov 2023 14:10:03 -0800 (PST) Date: Mon, 6 Nov 2023 14:09:58 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231106220959.296568-1-avagin@google.com> Subject: [PATCH 1/2 v2] fs/proc/task_mmu: report SOFT_DIRTY bits through the PAGEMAP_SCAN ioctl From: Andrei Vagin To: Andrew Morton , Muhammad Usama Anjum Cc: linux-kernel@vger.kernel.org, Andrei Vagin , "=?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?=" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 06 Nov 2023 14:10:23 -0800 (PST) The PAGEMAP_SCAN ioctl returns information regarding page table entries. It is more efficient compared to reading pagemap files. CRIU can start to utilize this ioctl, but it needs info about soft-dirty bits to track memory changes. We are aware of a new method for tracking memory changes implemented in the PAGEMAP_SCAN ioctl. For CRIU, the primary advantage of this method is its usability by unprivileged users. However, it is not feasible to transparently replace the soft-dirty tracker with the new one. The main problem here is userfault descriptors that have to be preserved between pre-dump iterations. It means criu continues supporting the soft-dirty method to avoid breakage for current users. The new method will be implemented as a separate feature. Cc: Muhammad Usama Anjum Cc: Micha=C5=82 Miros=C5=82aw Signed-off-by: Andrei Vagin --- v2: check the soft-dirty bit in pagemap_page_category Documentation/admin-guide/mm/pagemap.rst | 1 + fs/proc/task_mmu.c | 17 ++++++++++++++++- include/uapi/linux/fs.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin= -guide/mm/pagemap.rst index fe17cf210426..f5f065c67615 100644 --- a/Documentation/admin-guide/mm/pagemap.rst +++ b/Documentation/admin-guide/mm/pagemap.rst @@ -253,6 +253,7 @@ Following flags about pages are currently supported: - ``PAGE_IS_SWAPPED`` - Page is in swapped - ``PAGE_IS_PFNZERO`` - Page has zero PFN - ``PAGE_IS_HUGE`` - Page is THP or Hugetlb backed +- ``PAGE_IS_SOFT_DIRTY`` - Page is soft-dirty =20 The ``struct pm_scan_arg`` is used as the argument of the IOCTL. =20 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index ef2eb12906da..51e0ec658457 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1761,7 +1761,7 @@ static int pagemap_release(struct inode *inode, struc= t file *file) #define PM_SCAN_CATEGORIES (PAGE_IS_WPALLOWED | PAGE_IS_WRITTEN | \ PAGE_IS_FILE | PAGE_IS_PRESENT | \ PAGE_IS_SWAPPED | PAGE_IS_PFNZERO | \ - PAGE_IS_HUGE) + PAGE_IS_HUGE | PAGE_IS_SOFT_DIRTY) #define PM_SCAN_FLAGS (PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC) =20 struct pagemap_scan_private { @@ -1793,6 +1793,8 @@ static unsigned long pagemap_page_category(struct pag= emap_scan_private *p, =20 if (is_zero_pfn(pte_pfn(pte))) categories |=3D PAGE_IS_PFNZERO; + if (pte_soft_dirty(pte)) + categories |=3D PAGE_IS_SOFT_DIRTY; } else if (is_swap_pte(pte)) { swp_entry_t swp; =20 @@ -1806,6 +1808,8 @@ static unsigned long pagemap_page_category(struct pag= emap_scan_private *p, !PageAnon(pfn_swap_entry_to_page(swp))) categories |=3D PAGE_IS_FILE; } + if (pte_swp_soft_dirty(pte)) + categories |=3D PAGE_IS_SOFT_DIRTY; } =20 return categories; @@ -1853,12 +1857,16 @@ static unsigned long pagemap_thp_category(struct pa= gemap_scan_private *p, =20 if (is_zero_pfn(pmd_pfn(pmd))) categories |=3D PAGE_IS_PFNZERO; + if (pmd_soft_dirty(pmd)) + categories |=3D PAGE_IS_SOFT_DIRTY; } else if (is_swap_pmd(pmd)) { swp_entry_t swp; =20 categories |=3D PAGE_IS_SWAPPED; if (!pmd_swp_uffd_wp(pmd)) categories |=3D PAGE_IS_WRITTEN; + if (pmd_swp_soft_dirty(pmd)) + categories |=3D PAGE_IS_SOFT_DIRTY; =20 if (p->masks_of_interest & PAGE_IS_FILE) { swp =3D pmd_to_swp_entry(pmd); @@ -1905,10 +1913,14 @@ static unsigned long pagemap_hugetlb_category(pte_t= pte) categories |=3D PAGE_IS_FILE; if (is_zero_pfn(pte_pfn(pte))) categories |=3D PAGE_IS_PFNZERO; + if (pte_soft_dirty(pte)) + categories |=3D PAGE_IS_SOFT_DIRTY; } else if (is_swap_pte(pte)) { categories |=3D PAGE_IS_SWAPPED; if (!pte_swp_uffd_wp_any(pte)) categories |=3D PAGE_IS_WRITTEN; + if (pte_swp_soft_dirty(pte)) + categories |=3D PAGE_IS_SOFT_DIRTY; } =20 return categories; @@ -1991,6 +2003,9 @@ static int pagemap_scan_test_walk(unsigned long start= , unsigned long end, if (vma->vm_flags & VM_PFNMAP) return 1; =20 + if (vma->vm_flags & VM_SOFTDIRTY) + vma_category |=3D PAGE_IS_SOFT_DIRTY; + if (!pagemap_scan_is_interesting_vma(vma_category, p)) return 1; =20 diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index da43810b7485..48ad69f7722e 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -316,6 +316,7 @@ typedef int __bitwise __kernel_rwf_t; #define PAGE_IS_SWAPPED (1 << 4) #define PAGE_IS_PFNZERO (1 << 5) #define PAGE_IS_HUGE (1 << 6) +#define PAGE_IS_SOFT_DIRTY (1 << 7) =20 /* * struct page_region - Page region with flags --=20 2.42.0.869.gea05f2083d-goog