Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6860863rwb; Wed, 10 Aug 2022 02:23:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Kai2UFt9tGyWUWXPnq3F+NFf/4BH0wxaD6c/XCw1RENOkd/8LgsK7XIWk6eVhNYpQNT+T X-Received: by 2002:a05:6402:189:b0:437:8a8a:d08a with SMTP id r9-20020a056402018900b004378a8ad08amr25176182edv.241.1660123436635; Wed, 10 Aug 2022 02:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660123436; cv=none; d=google.com; s=arc-20160816; b=jeOEecpti/46nlC2tSmP6VH+cJWmohFRTgB+lPfPT9vKUJY4g8qWF8gi52NXekUFeg x0MX38W7NShFnT4NiLpdFut2BYzjV5ciXkETRpynQVVZuI0L1PrUzlPjF31uUtBCS80J cdf4p/oodU4wKFcECO62AxGHtF4aKTAcpd+70HaSy4GJK9vT6nZYtZIaVmRxaJm97YQw Lkpdd3wEA/MqT4F9RD5C1iXxSKQubE7jQDmmzZ744kdXt8IhXm6wgBGRzVW0kxT3vLHr ofkQhFQi4YeNRFlwKl3J2Vcq7tMQrhgsE8i4bIJPxNZJfz72vwJrIdF9rMp9OOnE9yCY qI2Q== 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:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=zDfT4OTVP3mlZybmyw3sBtbkZmpGAIdes/TJqqs05cY=; b=XuHQsyDYgYSPPwxpYGGhqYMwkpUmBBYDvqfx6Mt1vEh046eCgsGE45Q4ZsnolXGo2q hc1FGMtW/BjqEEo0chpqCiHvfz2b16DdXouBuKV9RkbNzUE76fQ/Kvog90HSJdb6KISA wbf6sJ6qTXkovTE+blULun8CiJBTLsTqhwVeZjY7Llb3GSKQfP9jnJ6hg1NjFqa6hRzn DHHGU3rAE6kpUXT+uH8v3xVOFZ11GjQs1RAR+Sza41Jamg011l9O53TjBjptk3RlDow7 RaQ55v6/mQFIoKPWpkfGtudH5coMQSofQssai0wTjq1+OzNDpEEPVCldK3yplKfb+ZBs 1SBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KKzgIFoy; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gy3-20020a170906f24300b0072a9d2d2d37si3821958ejb.116.2022.08.10.02.23.31; Wed, 10 Aug 2022 02:23:56 -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=@redhat.com header.s=mimecast20190719 header.b=KKzgIFoy; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231924AbiHJJDZ (ORCPT + 99 others); Wed, 10 Aug 2022 05:03:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231961AbiHJJDS (ORCPT ); Wed, 10 Aug 2022 05:03:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DD738868B5 for ; Wed, 10 Aug 2022 02:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660122197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zDfT4OTVP3mlZybmyw3sBtbkZmpGAIdes/TJqqs05cY=; b=KKzgIFoyfvRcdmri1ZFSg4PabPUr74q6WmaXDpVXSnEzrKtENaw4pdYFrrB5OKTOWBbK7U 4ouupo80IWEE+Za6XN9jytiJSAEuNNFW8CdyRO/vjAYo60NfYeqrjIGNsGqJewa9j7mHk4 7VI+vLB3mFXPx7azW7/3+X2pcvk55xY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-347-nCLjho4jPJeTKQLrnzCYXQ-1; Wed, 10 Aug 2022 05:03:14 -0400 X-MC-Unique: nCLjho4jPJeTKQLrnzCYXQ-1 Received: by mail-wm1-f72.google.com with SMTP id j36-20020a05600c1c2400b003a540d88677so3575536wms.1 for ; Wed, 10 Aug 2022 02:03:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=zDfT4OTVP3mlZybmyw3sBtbkZmpGAIdes/TJqqs05cY=; b=QvX9bBE42Tz+0myNMrrEoKgtaN4a8v/45KAVjHqHwOSipFiktzLjYfSpyMFRxF+gDk F0TGq2ALC3VZfj9U1pwhvsBHkLlb96UblpnOssTYco2wTHWKEREBDYaxM9Oq6Q83q80U ozskUJNUwcxYkMQKSIRJEfu2yR4s0xM2VSHf3F9oGi3F3D7lOSNkCZsAykCFBAbztgXH 9lNZn+YomDpkGI+4168JDG7MuIq8IFtc3HGUG+73WMBvROeTB5JO9oN9yRA1IAJdE4B0 4Psx09lH1s9P2D3cKEB/MMlu7V+owINT8HcKtPPLfjNeCvbNmUYXDs9ish9s3DpIs1n+ iTww== X-Gm-Message-State: ACgBeo0vBgkE8zbnLWlARPEjQMOR1Omx4jhUMH0Qf+OtTa7V9t2MDUoA RnYN0mplBtxASbfsB+wonl2BGVc7dyrfc7vQH+h9+NO/6qmXeP8l7J/iELd+RIaa2xO8CJrKKF3 +HZZUGFbFJcp7hnxh6sIZe1lm X-Received: by 2002:a5d:5a94:0:b0:221:6cec:2589 with SMTP id bp20-20020a5d5a94000000b002216cec2589mr15124093wrb.336.1660122193177; Wed, 10 Aug 2022 02:03:13 -0700 (PDT) X-Received: by 2002:a5d:5a94:0:b0:221:6cec:2589 with SMTP id bp20-20020a5d5a94000000b002216cec2589mr15124042wrb.336.1660122192829; Wed, 10 Aug 2022 02:03:12 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:1600:a3ce:b459:ef57:7b93? (p200300cbc7071600a3ceb459ef577b93.dip0.t-ipconnect.de. [2003:cb:c707:1600:a3ce:b459:ef57:7b93]) by smtp.gmail.com with ESMTPSA id i9-20020a05600c050900b003a3187a2d4csm1655413wmc.22.2022.08.10.02.03.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 02:03:12 -0700 (PDT) Message-ID: <95ed1a81-ff8e-2c48-8838-4b3995af51b7@redhat.com> Date: Wed, 10 Aug 2022 11:03:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Muhammad Usama Anjum , Jonathan Corbet , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Arnd Bergmann , Andrew Morton , Peter Zijlstra , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Shuah Khan , "open list:DOCUMENTATION" , open list , "open list:PROC FILESYSTEM" , "open list:ABI/API" , "open list:GENERIC INCLUDE/ASM HEADER FILES" , "open list:MEMORY MANAGEMENT" , "open list:PERFORMANCE EVENTS SUBSYSTEM" , "open list:KERNEL SELFTEST FRAMEWORK" , krisman@collabora.com Cc: kernel@collabora.com References: <20220726161854.276359-1-usama.anjum@collabora.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 0/5] Add process_memwatch syscall In-Reply-To: <20220726161854.276359-1-usama.anjum@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 26.07.22 18:18, Muhammad Usama Anjum wrote: > Hello, Hi, > > This patch series implements a new syscall, process_memwatch. Currently, > only the support to watch soft-dirty PTE bit is added. This syscall is > generic to watch the memory of the process. There is enough room to add > more operations like this to watch memory in the future. > > Soft-dirty PTE bit of the memory pages can be viewed by using pagemap > procfs file. The soft-dirty PTE bit for the memory in a process can be > cleared by writing to the clear_refs file. This series adds features that > weren't possible through the Proc FS interface. > - There is no atomic get soft-dirty PTE bit status and clear operation > possible. Such an interface might be easy to add, no? > - The soft-dirty PTE bit of only a part of memory cannot be cleared. Same. So I'm curious why we need a new syscall for that. > > Historically, soft-dirty PTE bit tracking has been used in the CRIU > project. The Proc FS interface is enough for that as I think the process > is frozen. We have the use case where we need to track the soft-dirty > PTE bit for running processes. We need this tracking and clear mechanism > of a region of memory while the process is running to emulate the > getWriteWatch() syscall of Windows. This syscall is used by games to keep > track of dirty pages and keep processing only the dirty pages. This > syscall can be used by the CRIU project and other applications which > require soft-dirty PTE bit information. > > As in the current kernel there is no way to clear a part of memory (instead > of clearing the Soft-Dirty bits for the entire processi) and get+clear > operation cannot be performed atomically, there are other methods to mimic > this information entirely in userspace with poor performance: > - The mprotect syscall and SIGSEGV handler for bookkeeping > - The userfaultfd syscall with the handler for bookkeeping You write "poor performance". Did you actually implement a prototype using userfaultfd-wp? Can you share numbers for comparison? Adding an new syscall just for handling a corner case feature (soft-dirty, which we all love, of course) needs good justification. > > long process_memwatch(int pidfd, unsigned long start, int len, > unsigned int flags, void *vec, int vec_len); > > This syscall can be used by the CRIU project and other applications which > require soft-dirty PTE bit information. The following operations are > supported in this syscall: > - Get the pages that are soft-dirty. > - Clear the pages which are soft-dirty. > - The optional flag to ignore the VM_SOFTDIRTY and only track per page > soft-dirty PTE bit Huh, why? VM_SOFTDIRTY is an internal implementation detail and should remain such. VM_SOFTDIRTY translates to "all pages in this VMA are soft-dirty". -- Thanks, David / dhildenb