From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9123AC25B06 for ; Wed, 10 Aug 2022 09:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231927AbiHJJD0 (ORCPT ); Wed, 10 Aug 2022 05:03:26 -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-Google-Smtp-Source: AA6agR7B/fed6AkUKvETZNZzY2Aw/ljCBjLPi20tQHr8C2p9Bwqnl1tq+PpkGuYpyjcrSsB3Ep52mA== 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 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