Received: by 2002:a05:6359:322:b0:b3:69d0:12d8 with SMTP id ef34csp392020rwb; Wed, 10 Aug 2022 09:53:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR6+eMuXLiEGXuDoERXs/nbldz6/muohvHq/P/XHPG24sWN2KQed4M8WXKIByjDeVRCVK0YW X-Received: by 2002:a17:907:a424:b0:732:e3d8:ec70 with SMTP id sg36-20020a170907a42400b00732e3d8ec70mr6346594ejc.666.1660150380895; Wed, 10 Aug 2022 09:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660150380; cv=none; d=google.com; s=arc-20160816; b=gmodcBN6TJks4OoAVfYX0VJXlFylRE5mabR2KY0U3w7HZPnouRJtMERATnDoM1IOso tKxLoW939Aa7azCVO0y1Le5sD/1GA9hJs6no+w0XYFa1uldk8I3my3bqZvjsa1CSeVHj yQlLnIQutXafnS30lirALDozX8n8bRy8CVbryEPkZvhEX4LXJoyog/HbUAJZEAph2edO RlaCFluVy8U4Gtj3vMCadpgXoIdiHqXLmNnWAOD4ZUwzOKouppf9oJwhcS/mrKLHOFou Q6Bd2Z/M4MbYuuEPaSvZSm7yq4nPGH0lfa3whcCj32GqInt4sd2TgNldUSZv9tHsJvpf AmzA== 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 :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=FHOXRw7YFjUMOWaZQbRHLmLOJ4lOoJH45LHsQ3weKnU=; b=h0DhUXWXsOTUSTn6la5D3fj9WGu/AvLw69jaTGFp4PL38Gz8yn5AKa6Og6b99NLSUr fzUNAQ4HXlDO843kGSwR8y0hlmDz/ANP538DEquiNwvP3lQQFTFYcfojulykCnel3ojz p7ExJonWPyeCSL0GkHZxNAgCcONH0EFNTn598uJOt7YputhDNGkBwEpS5q5euaWy37XY Cg8LlZJzdfV9bvMOPB6H+p6qBBQ+wvkMLEnZH5lHtc4E6A5sb0YgWlqPOiBMWrAX1M/9 nHADR+aQaX8s/mOdA1Tn7bfETiqRa5wGKiO9zk11sSXbnPVh81Em0DJa2SH/9KZipvC8 E7ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lKdpcLsk; 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=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a05640211cc00b0043e853919dfsi15083381edw.337.2022.08.10.09.52.34; Wed, 10 Aug 2022 09:53:00 -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=@collabora.com header.s=mail header.b=lKdpcLsk; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232617AbiHJQpX (ORCPT + 99 others); Wed, 10 Aug 2022 12:45:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbiHJQpV (ORCPT ); Wed, 10 Aug 2022 12:45:21 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B9FB13FB6; Wed, 10 Aug 2022 09:45:20 -0700 (PDT) Received: from [192.168.58.158] (unknown [43.245.8.143]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id 3D75B6601C6F; Wed, 10 Aug 2022 17:45:02 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1660149918; bh=ADpakFyntTu99bJzdscZwFQJz67HrXhODiRO4Yo+iOI=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=lKdpcLsk+CEqi1feuozbCvLy9PorC/6CTbR+EZZbN8BUSPMDV+pWYORnjs8zYZ5cQ QW5tCSakmDw7Bd5vVbCyiNDr5uw255ZDqOCOf1A+Rp6yfR8gqE170BNTf9IiSgyCYx liuew+5mFZt5vJYS9+Op9FUeF6CpmFt6bqcrb032wgRXiCKLLmUcRFdMUoImwf6MjG Q4cY431DqQNJtV6dQ+VjAEb8uLbqlHx+wTRKhkkKivBLIYpvEOK+izDbtG3uoynwiQ TtXaDP1rctfUMitL60FRBtlVdrbP/Luo6qigN5naPnELJorUr/VET9wKhEB4IKqjwH RBJxKF8DmRwnQ== Message-ID: <89bbe03c-694d-f8b7-f4d9-38277b48bd22@collabora.com> Date: Wed, 10 Aug 2022 21:44:55 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Cc: usama.anjum@collabora.com, "kernel@collabora.com" Subject: Re: [PATCH 0/5] Add process_memwatch syscall Content-Language: en-US To: "Peter.Enderborg@sony.com" , 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" References: <20220726161854.276359-1-usama.anjum@collabora.com> <456a8052-dfd2-e00c-6da7-fb5aa0c35f2c@sony.com> From: Muhammad Usama Anjum In-Reply-To: <456a8052-dfd2-e00c-6da7-fb5aa0c35f2c@sony.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 8/10/22 2:22 PM, Peter.Enderborg@sony.com wrote: > On 7/26/22 18:18, Muhammad Usama Anjum wrote: >> Hello, >> >> 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. >> - The soft-dirty PTE bit of only a part of memory cannot be cleared. >> >> 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 >> >> 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 >> > > Why can it not be done as a IOCTL? It can be done as ioctl. I think this syscall can be used in future for adding other operations like soft-dirty. This is why syscall has been added. -- Muhammad Usama Anjum