Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp931264rdf; Fri, 3 Nov 2023 23:10:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxqKf3mxJGOANxmvYiwsMu0rkOVEtWjN2UhSg32oe9OMtaix7XGnxDmI9J1w0Tt/poXgwO X-Received: by 2002:a17:90b:1845:b0:280:963d:9cb with SMTP id mf5-20020a17090b184500b00280963d09cbmr6025440pjb.23.1699078243985; Fri, 03 Nov 2023 23:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699078243; cv=none; d=google.com; s=arc-20160816; b=UkM426rvkuMsJXGSAOZDmB0h3tY1cjFB30N6YHtWY39KbGHFVrDmVNA+ytF3Q5MY+t 2Xd9fx7p6VaT7XcqlN6Ba3xJiAjpc97WGbe1kDm2FUar1P/kL0IsuQ7qvrXNS0OkvyC/ vfEs/x1fBE3I4BvlezeAmUpdsrWU9JWVJVyhf3IPI/MdoRf1a8f9ACuXic/3GrkoqwKw bIVa8Kev4bQH3hfFoLvQRWCCdWvj0dzfL83ewKzSM9c8PQSawVcMkri4NDq6Uf5Xh1ga v12hW73cBVY5OWAUXUMbrd0Tjt6n4+eGorIcNakS5ef4ELYQXGkC73A7DIL6ygvgCR/8 IOwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:to:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=GzB33vB3RwytOphVv0F/0BzZ0QKNgL04EnpMujBAxpQ=; fh=6aUA3QH/BELy7pFY7068JW6VQ3w9U9fPPI4Y3nF4Pq4=; b=arTt5LtBFBtZHI8BKPBjJ42PimfRDLOe0JAp0y8JEEAEyAgsLOr7tO1saGsYYuItXo YlKEOlJJJSJS00P2X0GjzJupFFFxHHNkSYMGOxQhavgwf23wXVEj47o4dHYWPRbuRHHj 8GUmsvMyQ1ylymdG/gFKZfowvoY/3yIqDJ2GihK6jO8brd2dvIwadccJNV7bJFa/7TJc bYLYQ5n/OtiOUyheMvIdzCYJnduca459Ju2p50ktuz9UDg6K7sL4sk009Czhbs60aSp7 +baFLfJAu/E4w4IPm8lzRVOOJsjfLAyWDa+KSrElCLqK/OMNpR/SbH6E6/J/zu0zloro DTMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YrWcctDw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c4-20020a17090abf0400b00274d6373fe1si3201142pjs.120.2023.11.03.23.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 23:10:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YrWcctDw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EDEA881DFD62; Fri, 3 Nov 2023 23:10:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231199AbjKDGJ2 (ORCPT + 99 others); Sat, 4 Nov 2023 02:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjKDGJ1 (ORCPT ); Sat, 4 Nov 2023 02:09:27 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ADEBD4C for ; Fri, 3 Nov 2023 23:09:24 -0700 (PDT) Received: from [100.98.85.67] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id 9E5826607413; Sat, 4 Nov 2023 06:09:21 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1699078162; bh=G/GaJjDya/fLTXGC5dp+Xj68bRYVj9L1edFwNi6kOkY=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=YrWcctDwO9a7LcfrVPjqGYfnbSiD4y1R209aa9KUFRad6haouajJIZZS4LAFXi4pT /7GqdOTSMy4Aag3mxmKaaAeHSDeHamNooVhp7j2adVql6frajEoWmsLBDkENz/KJ+U yoPa4sIIKUbmcIZgLiR1jodKXCb123+tALjVJh3BffcJRWkniNfj+CrYIq6akKDUHF e2gz9lsXSRJJBXAB3sfqG3KdGSQ+pm0ZkQGwBC2HppP/UUIDFD5dy1uyZ0ruUsdZI2 eBF6HIRiTI7DMrmjk2RjUIH0hJIk6aQEjDk7Q8xatCYiQwKAW3vdJIgEf0Bi6xvO8I fsZbGfvVtaftQ== Message-ID: <102e7f6c-5c99-407f-8696-dd71efcc16f6@collabora.com> Date: Sat, 4 Nov 2023 11:09:17 +0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: Muhammad Usama Anjum , linux-kernel@vger.kernel.org, =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: Re: [PATCH] fs/proc/task_mmu: report SOFT_DIRTY bits through the PAGEMAP_SCAN ioctl To: Andrei Vagin , Andrew Morton References: <20231102173357.446157-1-avagin@google.com> Content-Language: en-US From: Muhammad Usama Anjum In-Reply-To: <20231102173357.446157-1-avagin@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 03 Nov 2023 23:10:35 -0700 (PDT) On 11/2/23 10:33 PM, Andrei Vagin wrote: > 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ł Mirosław > 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, struct 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) > > struct pagemap_scan_private { > @@ -1853,12 +1853,16 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p, Probably missed the pagemap_page_category() for normal pages. Add PAGE_IS_SOFT_DIRTY support for normal pages in pagemap_page_category() just like pagemap_thp_category(). tools/testing/selftests/mm/soft-dirty.c can be updated to test if we are getting the exactly same data from the ioctl. > > if (is_zero_pfn(pmd_pfn(pmd))) > categories |= PAGE_IS_PFNZERO; > + if (pmd_soft_dirty(pmd)) > + categories |= PAGE_IS_SOFT_DIRTY; > } else if (is_swap_pmd(pmd)) { > swp_entry_t swp; > > categories |= PAGE_IS_SWAPPED; > if (!pmd_swp_uffd_wp(pmd)) > categories |= PAGE_IS_WRITTEN; > + if (pmd_swp_soft_dirty(pmd)) > + categories |= PAGE_IS_SOFT_DIRTY; > > if (p->masks_of_interest & PAGE_IS_FILE) { > swp = pmd_to_swp_entry(pmd); > @@ -1905,10 +1909,14 @@ static unsigned long pagemap_hugetlb_category(pte_t pte) > categories |= PAGE_IS_FILE; > if (is_zero_pfn(pte_pfn(pte))) > categories |= PAGE_IS_PFNZERO; > + if (pte_soft_dirty(pte)) > + categories |= PAGE_IS_SOFT_DIRTY; > } else if (is_swap_pte(pte)) { > categories |= PAGE_IS_SWAPPED; > if (!pte_swp_uffd_wp_any(pte)) > categories |= PAGE_IS_WRITTEN; > + if (pte_swp_soft_dirty(pte)) > + categories |= PAGE_IS_SOFT_DIRTY; > } > > 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; > > + if (vma->vm_flags & VM_SOFTDIRTY) > + vma_category |= PAGE_IS_SOFT_DIRTY; > + > if (!pagemap_scan_is_interesting_vma(vma_category, p)) > return 1; > > 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 Add this identical change in tools/include/uapi/linux/fs.h as well. > @@ -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) Maybe one or couple of lines about it in the pagemap.rst. > > /* > * struct page_region - Page region with flags -- BR, Muhammad Usama Anjum