Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3678719rwd; Fri, 16 Jun 2023 23:46:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6crLPknm3eO945azeM39S8RSMxq27HsuQbU/J/U1Odho8zWLCy51xjfJsHi0XZgYu3ieDu X-Received: by 2002:a17:902:c40c:b0:1b5:3aed:b078 with SMTP id k12-20020a170902c40c00b001b53aedb078mr3560517plk.53.1686984369538; Fri, 16 Jun 2023 23:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686984369; cv=none; d=google.com; s=arc-20160816; b=w42eJxPgW+HauGIYY4ET7RyQ0JPWv9Gga4mIk7reO/owvSdC9iGuhcgLsgp+j2bUfu eoEkAkNajaZ9ctXghm/ISRc7k/7/q9+drsKbWftImirrWYZ6s0dGrHrwOK6/gtrHAqDQ ocBjUD9MEF8wF1NY2fh45R5J/yP5df8SfS48SM88Gm06A5Jo2Cu6juHIQHOkL6NN90gX UxvXaKbhcnsdvidku6LnnZNMVFqlRsMf+VaOuTfV9uFTxkLlU4/YnMRMrkgo4NkvfT0F DC2PBGDhK4wZGslbU8DVNxBPq9M2mTvEGFay1whM7spiGPVkO1QoUvME40I1A4sbRkeF NkWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Crj4AOYfyqhNznIGfJkLyC4r78ZNyHEK1sC4/e8zC8Q=; b=QmgmWVXGLUz/Zl28J97WZ448ByIuTJoJPJ/3uD3LwuxDB6kgplnsu/vw+TzSDACcTx v4euFdFju5aqPV+c5nIpZdJZy8f5liOvKZe0Ini7R0mpIhwQyrns5QfCrKAIa0VoqZIN ATcKKUrNcBcjFUzYCXNqaZFHrjGfCAKAoEBjLo1PkjdZyWpi6Yol00INKFhnfvuQcenB Z6T8stW8LaYQ611g235z0KfB1pjNA7NTdcoXtXLzCLcPo25I+1l/1toT26rwCUOA+Yzj LTo6qZs765WWAhgzZNVi3rtR1b8ckafAukRLcu/l++N57XY+V01SNaU8bPKIXppOUb2Z 4ARw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fklUhfQK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a6557ca000000b0053070cb6da8si5279484pgr.99.2023.06.16.23.45.55; Fri, 16 Jun 2023 23:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fklUhfQK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233754AbjFQGjb (ORCPT + 99 others); Sat, 17 Jun 2023 02:39:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbjFQGj1 (ORCPT ); Sat, 17 Jun 2023 02:39:27 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95D0F2721; Fri, 16 Jun 2023 23:39:26 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b51780bed0so12601325ad.3; Fri, 16 Jun 2023 23:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686983966; x=1689575966; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Crj4AOYfyqhNznIGfJkLyC4r78ZNyHEK1sC4/e8zC8Q=; b=fklUhfQKPt3Iry+A81Ec6X7AIUzJQZpIBbAmaM/YPmosETutG7a+zNYvNhcR28P6j2 XciQcchKtNnSc7bI+cSL8fp94+Kk4sUWdSOfZwzownoKuiXuujRmd5bCJ7IXerO51mgF PRlYSlBIPJWcDnU3DLNmrjxmg7D+1lw5okkBNVTrDK/e4xPFZeWFGBkdoo5Cg9vi2/ex HDEHDElQa3co2pRoY5jPEFfXJVJd1yXhH/mms7macwkv53PJy6lrV9uWWySCBOt/1S3y aDh5ov9YjW7hi+WOKOpjJ0KIjhfToJR2hVCq0yzV9Aq2RSbv7XOonbWfRGBpwA0ZWhfx 5Ncw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686983966; x=1689575966; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Crj4AOYfyqhNznIGfJkLyC4r78ZNyHEK1sC4/e8zC8Q=; b=hvsxYd2lb0xp4ruR2YZo5wEknOv/kpwgNvjF9Q7VHHUH6nReIXiVQ1h6oDNIJTcUW5 9vAHDUkqe0oL3dMIKDqf0b5uIuOtMT6wafU+Ssc5cUSuAj8Gch6j7FdRYW3kX3chOhY+ tt488QgsEi85pPqbMYDugvZTQ5q9QPVXulebU7ZqE4BIbBTZUStnC57lclt2zbfbBDmd wd7ATnFJ355Uey3glJyf1TYKuos8fAhk3hiPiOzxyAoOCMDH5TGyuLmlnWbdZpQ9Vvyd uxMFdt9cMeDbBnnhdzwU8KBFTc+vkQ+TADXIgXoBHZbsBrQQwXdtVSS+9ekWkZztP2dA pXJQ== X-Gm-Message-State: AC+VfDy9dL81ybGU4pNo672+1Xa/l28E0m7FmBLyAiptwj2ZtoSlAM5E 3IXyVseDcPuoPpkXtip7Rmg= X-Received: by 2002:a17:903:22c4:b0:1b0:5c0a:3f80 with SMTP id y4-20020a17090322c400b001b05c0a3f80mr5552777plg.44.1686983965905; Fri, 16 Jun 2023 23:39:25 -0700 (PDT) Received: from gmail.com ([2601:600:8500:5f14:d627:c51e:516e:a105]) by smtp.gmail.com with ESMTPSA id w20-20020a1709029a9400b001b536aaf7c2sm1898337plp.189.2023.06.16.23.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 23:39:25 -0700 (PDT) Date: Fri, 16 Jun 2023 23:39:22 -0700 From: Andrei Vagin To: Muhammad Usama Anjum Cc: Peter Xu , David Hildenbrand , Andrew Morton , =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Danylo Mocherniuk , Paul Gofman , Cyrill Gorcunov , Mike Rapoport , Nadav Amit , Alexander Viro , Shuah Khan , Christian Brauner , Yang Shi , Vlastimil Babka , "Liam R . Howlett" , Yun Zhou , Suren Baghdasaryan , Alex Sierra , Matthew Wilcox , Pasha Tatashin , Axel Rasmussen , "Gustavo A . R . Silva" , Dan Williams , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Greg KH , kernel@collabora.com Subject: Re: [PATCH v19 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs Message-ID: References: <20230615141144.665148-1-usama.anjum@collabora.com> <20230615141144.665148-3-usama.anjum@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <20230615141144.665148-3-usama.anjum@collabora.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FSL_HELO_FAKE, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 15, 2023 at 07:11:41PM +0500, Muhammad Usama Anjum wrote: > +static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start, > + unsigned long end, struct mm_walk *walk) > +{ > + bool is_written, flush = false, is_interesting = true; > + struct pagemap_scan_private *p = walk->private; > + struct vm_area_struct *vma = walk->vma; > + unsigned long bitmap, addr = end; > + pte_t *pte, *orig_pte, ptent; > + spinlock_t *ptl; > + int ret = 0; > + > + arch_enter_lazy_mmu_mode(); > + > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > + ptl = pmd_trans_huge_lock(pmd, vma); > + if (ptl) { > + unsigned long n_pages = (end - start)/PAGE_SIZE; > + > + if (p->max_pages && n_pages > p->max_pages - p->found_pages) > + n_pages = p->max_pages - p->found_pages; > + > + is_written = !is_pmd_uffd_wp(*pmd); > + > + /* > + * Break huge page into small pages if the WP operation need to > + * be performed is on a portion of the huge page. > + */ > + if (is_written && IS_PM_SCAN_WP(p->flags) && > + n_pages < HPAGE_SIZE/PAGE_SIZE) { > + spin_unlock(ptl); > + > + split_huge_pmd(vma, pmd, start); > + goto process_smaller_pages; > + } > + > + bitmap = PM_SCAN_FLAGS(is_written, (bool)vma->vm_file, > + pmd_present(*pmd), is_swap_pmd(*pmd)); > + > + if (IS_PM_SCAN_GET(p->flags)) { > + is_interesting = pagemap_scan_is_interesting_page(bitmap, p); > + if (is_interesting) > + ret = pagemap_scan_output(bitmap, p, start, n_pages); > + } > + > + if (IS_PM_SCAN_WP(p->flags) && is_written && is_interesting && > + ret >= 0) { > + make_uffd_wp_pmd(vma, start, pmd); > + flush_tlb_range(vma, start, end); > + } > + > + spin_unlock(ptl); > + > + arch_leave_lazy_mmu_mode(); > + return ret; > + } > + > +process_smaller_pages: > +#endif > + > + orig_pte = pte = pte_offset_map_lock(vma->vm_mm, pmd, start, &ptl); > + if (!pte) { Do we need to unlock ptl here? spin_unlock(ptl); > + walk->action = ACTION_AGAIN; > + return 0; > + } > + > + for (addr = start; addr < end && !ret; pte++, addr += PAGE_SIZE) { > + ptent = ptep_get(pte); > + is_written = !is_pte_uffd_wp(ptent); > + > + bitmap = PM_SCAN_FLAGS(is_written, (bool)vma->vm_file, > + pte_present(ptent), is_swap_pte(ptent)); The vma->vm_file check isn't correct in this case. You can look when pte_to_pagemap_entry sets PM_FILE. This flag is used to detect what pages have a file backing store and what pages are anonymous. I was trying to integrate this new interace into CRIU and I found one more thing that is required. We need to detect zero pages. It should look something like this: #define PM_SCAN_FLAGS(wt, file, present, swap, zero) \ ((wt) | ((file) << 1) | ((present) << 2) | ((swap) << 3) | ((zero) << 4)) bitmap = PM_SCAN_FLAGS(is_written, page && !PageAnon(page), pte_present(ptent), is_swap_pte(ptent), pte_present(ptent) && is_zero_pfn(pte_pfn(ptent))); Thanks, Andrei