Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp540579rdb; Thu, 2 Nov 2023 10:34:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvWLFJivM7Rice65Z5CbiCFs1qBlxfpEf0DQjzonQRr2wdoUdOVGu7iQngfQTrslV6mRRh X-Received: by 2002:a05:6a20:3941:b0:181:8654:8272 with SMTP id r1-20020a056a20394100b0018186548272mr3980543pzg.2.1698946469118; Thu, 02 Nov 2023 10:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698946469; cv=none; d=google.com; s=arc-20160816; b=wvAPPJdRyqLCMBsiRs0ek58fzCzsnBYIsCYhZcftsjm6kUpt0ifCMUh5Jv6sCW5Bq6 gF7/+sxhm9cZIaelORp8lFNIJPhdrrJYYgXq8nQkva7zAaK6PnHHIngqCsTxHx4Z0AsH cKsCCfmYeLpRzVkL5qnrBEIxVh/f0u1zFeYG4N+PBfcCzRRtXxMg0jRAOrhRF4NxlHdp VP/o5YGM4dWHHMrd1rYGywKmTxcYmizwo4tpQz01JZDrsTLo7RfFxjrI/ONevFeFD5mG VHkuwAF/Da2cMaaIwTpbqOmj95gArMMetzRuMKlkNqf/wheGooS8YgR7uk1IOEVS0E0D rvYw== 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=t9YpU4ldQQXi82QJZDUwjxQ3rP5Gle0TPFZjnEHYbWE=; fh=r8pIO74m6RxQcs0DUwEWeArobKUZTA6j0g/QJOb1cS8=; b=EanvnZe1Ad0qf7NEWS1Ml6NclBI+6+xMVtuE2TF4aOMUltpx0xdjqELJxEfmuPtO38 Vue9hG/2CCVHdObKfj/wm0hKRMi4JDD1BRoo9+20IWwgkjPg/6UkXAaMd7RBBlygfFAN i+ATk7TfZsvQtzT/famEQB/gg+079pYXFsmo04j8koCSJZGz3vDSAeiv0ORlcV6Db9Cm QA5mqJULTgMYRZ2wX4tMsg7Nex8/sy8ImQjX+jf4nW6lEiwsCPnoHQbMh+YCs9c8qM6x WhBdaxYZzmH0f9F/eVqoZZpoUw4/OyuI5wvwUHcgWDf0hK/jE9AXXWGFDGQLqU6bG+xJ P+Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=iAO77EFA; 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 j3-20020a056a00130300b006c349641c3csi40129pfu.143.2023.11.02.10.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 10:34:29 -0700 (PDT) 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=iAO77EFA; 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 49443816039E; Thu, 2 Nov 2023 10:34:26 -0700 (PDT) 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 S229479AbjKBReG (ORCPT + 99 others); Thu, 2 Nov 2023 13:34:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233328AbjKBReE (ORCPT ); Thu, 2 Nov 2023 13:34:04 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8947E19D for ; Thu, 2 Nov 2023 10:34:00 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7c97d5d5aso17334167b3.3 for ; Thu, 02 Nov 2023 10:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698946439; x=1699551239; 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=t9YpU4ldQQXi82QJZDUwjxQ3rP5Gle0TPFZjnEHYbWE=; b=iAO77EFAgcWddLYuZKXE9qepfSt6IFGJwn6Vit91jtNgivH798craudB87DgqA4NI0 yF9laVx2Io+TwAd4gr1Zc85YHGhaVxfUYaHtigsJX8huOk0ZOwUaK0mBAob9/GdF191B l2UqC1RYW2QGmNrgrGBeoBKM+bjRVc7b3HuTWPKu22YUHjGefkAKeuoTYZvSOKLNc8GL z7W0GwINg+hLMrPitsGGY9hvcx3Yc66SWKOChppm+P1w0Zqsx0W/K1CVb32RjYm7vHUp Wc+VmsLV+pvB6DNz7ciZ2pMs/bxVBfYyLtez6UPSytbozioAJsSVb5ZBCbcEqTwWZ1mB QIXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698946439; x=1699551239; 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=t9YpU4ldQQXi82QJZDUwjxQ3rP5Gle0TPFZjnEHYbWE=; b=dxvM97UemH4scW7O4g2pYSuMmO14QlhDy+UBmMZ9jD2RQVyf1rp3kSbPhGjqCDRhG1 bi9egbf9DYdQi314aLHQOWlX8N2wij1t2Y+6iC/zj++lYLWlplSbdeWVf38u/ukEvqKi 9iFbgchiKemWe+7o5Kbf2Pr62ps393GEbRymfYyeEstF4fUFTO89iWGhGHAxqyblxA9w U6vRUe9SmmjzPMmsSfzGnV7jZzuGLEfttlWPGuXec5IProQ1wVgten4quYNcQJz7ZHFP pJqnhL6Fra1zJBlrjgvgrtITzHvcThCx9aPUgKN40ANiJS9igZ20YHY3xknoJvRKuxOa ILAg== X-Gm-Message-State: AOJu0Yyv4oliYf97tG6pPO1oXDHsZCrdOgtAfMbKIEF0Jrrjr/ycdWfg 3FRTQ8oIO72MMTkDT2ZVjwQ5L70twl4= X-Received: from avagin.kir.corp.google.com ([2620:0:1008:10:a803:d728:acb2:4622]) (user=avagin job=sendgmr) by 2002:a0d:ea41:0:b0:5a7:aa51:c08e with SMTP id t62-20020a0dea41000000b005a7aa51c08emr7033ywe.1.1698946439720; Thu, 02 Nov 2023 10:33:59 -0700 (PDT) Date: Thu, 2 Nov 2023 10:33:57 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231102173357.446157-1-avagin@google.com> Subject: [PATCH] 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]); Thu, 02 Nov 2023 10:34:26 -0700 (PDT) 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 --- fs/proc/task_mmu.c | 13 ++++++++++++- include/uapi/linux/fs.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index ef2eb12906da..cefa676bd33b 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 { @@ -1853,12 +1853,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 +1909,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 +1999,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