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 77C41C25B0C for ; Wed, 10 Aug 2022 09:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231908AbiHJJDY (ORCPT ); Wed, 10 Aug 2022 05:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbiHJJDR (ORCPT ); Wed, 10 Aug 2022 05:03:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A8AC686C02 for ; Wed, 10 Aug 2022 02:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660122195; 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=K41H2IPUCe719RNH+3PxUB4HiOEMzqAiee70EBMEGPSp+05paCus67bm6WKAsbeu5BpVQS wNVujc69GzXls0AaUIWivGtx5X9Nm+/StgrSCVgF9u/z3YcGHqRvDIXabKYN0pTIoxdqdM f+pb2iJqDG8dGHrVZifT+JOO55CEu9w= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-482-2QhNOtMIO22iluImoIHTkg-1; Wed, 10 Aug 2022 05:03:14 -0400 X-MC-Unique: 2QhNOtMIO22iluImoIHTkg-1 Received: by mail-wm1-f70.google.com with SMTP id h62-20020a1c2141000000b003a4f57eaeaaso1893163wmh.8 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=Hb0AHcWszZi4x7VSNAkpqG+LP46FmrSOUxtc8luh9GICy4wNxwHm21mXzD8hQj9qtv J2bLw+CIoHvmKF/4amCbfrZOVN44hN2rvWP47AJoMvlNQid64Li0KjkxJtI4yO1blu3I mypN162s4PfKYfQ01Baotc2Bg2+/SeYEAVzZU8gomUXzhLElrYMASJBxfxOazV5WJQa6 xtf+4gG4DMpu8iQD05ZTZe2DOGvyzQr1zZNvfrYh2B5JDB+I6yGPLRvBlkOqdFnW5bf4 qbvj4XJ5B1GrOWYALxcxhoZREW0XnhBlt4bXULT0LFDU3fUktzqrPzuK1CQfFQWdMRmW 76zQ== X-Gm-Message-State: ACgBeo1gNitzll9/aSPVDn11rWeS0EYIFgBznthqjNXxMd2MRz5gZLVo zXMGlHLmuCIPgZ5SNGuVqPG6BR4s9kCCzQyRG+wVfKydyfA6jF1A9ZmsNwT0THwOj+9PXA705v9 BY7XZ+t/e+J6L9hLFfDmN X-Received: by 2002:a5d:5a94:0:b0:221:6cec:2589 with SMTP id bp20-20020a5d5a94000000b002216cec2589mr15124076wrb.336.1660122193175; 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-api@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