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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48A10C636D6 for ; Wed, 22 Feb 2023 11:48:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF93A6B0071; Wed, 22 Feb 2023 06:48:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA9966B0073; Wed, 22 Feb 2023 06:48:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 971C06B0074; Wed, 22 Feb 2023 06:48:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8AC186B0071 for ; Wed, 22 Feb 2023 06:48:30 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5DCE8C0B34 for ; Wed, 22 Feb 2023 11:48:30 +0000 (UTC) X-FDA: 80494755180.12.C5AA3D6 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by imf25.hostedemail.com (Postfix) with ESMTP id 6F705A002C for ; Wed, 22 Feb 2023 11:48:27 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UqDS+6tq; spf=pass (imf25.hostedemail.com: domain of emmir@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=emmir@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677066507; h=from:from:sender: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:dkim-signature; bh=u0SkOKRxQb31uA959ab+LjFmT74FnfTe8YzbdQveaiY=; b=THsfbE/R8n3b7lh/VGU3RqUMaAor1tIsLrIbdMLZ9aAJe5TA+g/DDYentida01b3Ej72UU YwzJKExb2mdmfhpKxHoNpLUnVQopl5F7tDYrToZRKzYfkASKGQARENyAT08WI11+wNQZyY Js4nCfR91PPD8A32fmsnhztpH0DP72Q= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UqDS+6tq; spf=pass (imf25.hostedemail.com: domain of emmir@google.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=emmir@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677066507; a=rsa-sha256; cv=none; b=wOvnCXHP2Nb9HgbRZw0+ajiCsN5/20hz2sgvIqZG6QPhs7ta8INULm8akaH11ztzZPQF+B 7x3c7d9nX97uDuqifvN5pqJEdXD/Keh5qt7WnlxD0GJB//9FDSuG/ew4rf6mRiFlN93NVh tGZm03SOcvEk+fZqh5Hh/Gf3+rEWeuM= Received: by mail-ed1-f52.google.com with SMTP id f13so28684788edz.6 for ; Wed, 22 Feb 2023 03:48:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=u0SkOKRxQb31uA959ab+LjFmT74FnfTe8YzbdQveaiY=; b=UqDS+6tqNYyjqohkN0RYnKWLUOdzlgyc8hyv0ooxuSLy2PIILQb1K4desrZLIb09DP MZVlPweGs4gOkRLk8WL/QYenJ4HLb3H7CtMPHKaTcuBXkzLmXH1Qa+wDP0wsqhAcRzco r1K2i0iPhcZbgToPRI4vyBH6sO8JggrUXhuS5ISy03nEazNH9t/MQRFYmU7lkHV2E0rL KoOgG2YEoYcAptDBxjJCyy1TDAo8OXHo/Q/mPZ7YncRmGQL/quWx3FlKCvlr8IZ/2oCX OjsCCtkkOKtFrAR6GvA//DLeDNTUotumhmaBWsa2KXYn9wcuEvePHKi20W1yQXRLwOiv tGbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u0SkOKRxQb31uA959ab+LjFmT74FnfTe8YzbdQveaiY=; b=ObElLTVzuvTdqKbQqguItJfn9W4f2zG1+UxbUSUvME3D8nQ0iUTK/i95OBQidpZd/V Ts0a5zl5CGVM/sHRCzZNcgpxIuZyxPGrbdnXJfoEeNA3SNzZd0Bscl4/DFdhv0+aQM+A DlkQnJXueVuwBiTUntRW/HBlEfQ3ROaC0seXIEx4fXsY4+UNhgfKL3V1qP58EVbEJtdP PpytMtuPSbwGfZSq4kyR2ze2IDOjXXF5lRuU5lC+H86pok8iYSQaepp4YMEPlfuGkFaQ gwbhLy0b0VWCKiiBPOLVaCx4E6nmqVAZp5Sr4G+pRSxx9Y83uhWkUFavhtAFuJkjFH6A bgpQ== X-Gm-Message-State: AO0yUKXjDxmODkRK20wsdSxNLmgckeW5l/BNz7u0zqannya6WA4Zuq4G WyYkJwe+8rQe6DiC/VkemI9lhtKGEOAYacaRoxeyaQ== X-Google-Smtp-Source: AK7set+7jDBY525NdRoBeszWKhBVRicR26iUfAdJlIK3aE5RKh3n+8X38UCVRCGGxqOdSWAvqZonp5dnF09jL/p8IDM= X-Received: by 2002:a17:906:eb4d:b0:87b:dce7:c245 with SMTP id mc13-20020a170906eb4d00b0087bdce7c245mr7249278ejb.3.1677066505580; Wed, 22 Feb 2023 03:48:25 -0800 (PST) MIME-Version: 1.0 References: <20230202112915.867409-1-usama.anjum@collabora.com> <20230202112915.867409-4-usama.anjum@collabora.com> <36ddfd75-5c58-197b-16c9-9f819099ea6d@collabora.com> <6d2b40c6-bed9-69a6-e198-537b50953acd@collabora.com> In-Reply-To: From: =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Date: Wed, 22 Feb 2023 12:48:13 +0100 Message-ID: Subject: Re: [PATCH v10 3/6] fs/proc/task_mmu: Implement IOCTL to get and/or the clear info about PTEs To: Muhammad Usama Anjum Cc: Andrei Vagin , Mike Rapoport , Nadav Amit , David Hildenbrand , Andrew Morton , Paul Gofman , Cyrill Gorcunov , Alexander Viro , Shuah Khan , Christian Brauner , Yang Shi , Vlastimil Babka , "Liam R . Howlett" , Yun Zhou , Suren Baghdasaryan , Alex Sierra , Peter Xu , 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, Danylo Mocherniuk Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 6F705A002C X-Stat-Signature: kpgxcxetpksacxjhtdzr3oar6gxub11c X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677066507-327176 X-HE-Meta: U2FsdGVkX19wL6lPM5Xih8/j3gvlZeg1vv4dNFq8BwFLNdpxZ8yWhyrTou/M9WfjqMiO5aa0/cH2JmDOgLVwStkCVwyJd9tVElfAt3PuK5ybpNetok0wQm5mkHMfcnjWttEGlOGD+Y2QrDa+Bl8cdoE8tSAxo4IDCLhwVVgo2k0R/O+IqnTK8d8NTr12PTYLmo+4DLlPm3/eJB6fTkOnE+8JGmbTdiL1AYGkW0qw5K7ZBTJ7yDXS/7PcDQFMqBUtieCBsTxlQXViZklrsVpHadJt5e0PwVoBtyNKhvtLRGm3Dai7csFTWyeYS48NVCka/Z+ZBefJQ9fQhEh1toCL724cpyai9TIX+4wuymgP8SCjVA+FiEDrfDjMjIFLT9uYi4frQkcNhM05L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ner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, 22 Feb 2023 at 12:06, Muhammad Usama Anjum wrote: > > On 2/22/23 3:44=E2=80=AFPM, Micha=C5=82 Miros=C5=82aw wrote: > > On Wed, 22 Feb 2023 at 11:11, Muhammad Usama Anjum > > wrote: > >> On 2/21/23 5:42=E2=80=AFPM, Micha=C5=82 Miros=C5=82aw wrote: > >>> On Tue, 21 Feb 2023 at 11:28, Muhammad Usama Anjum > >>> wrote: > >>>> > >>>> Hi Micha=C5=82, > >>>> > >>>> Thank you so much for comment! > >>>> > >>>> On 2/17/23 8:18=E2=80=AFPM, Micha=C5=82 Miros=C5=82aw wrote: > >>> [...] > >>>>> For the page-selection mechanism, currently required_mask and > >>>>> excluded_mask have conflicting > >>>> They are opposite of each other: > >>>> All the set bits in required_mask must be set for the page to be sel= ected. > >>>> All the set bits in excluded_mask must _not_ be set for the page to = be > >>>> selected. > >>>> > >>>>> responsibilities. I suggest to rework that to: > >>>>> 1. negated_flags: page flags which are to be negated before applyin= g > >>>>> the page selection using following masks; > >>>> Sorry I'm unable to understand the negation (which is XOR?). Lets lo= ok at > >>>> the truth table: > >>>> Page Flag negated_flags > >>>> 0 0 0 > >>>> 0 1 1 > >>>> 1 0 1 > >>>> 1 1 0 > >>>> > >>>> If a page flag is 0 and negated_flag is 1, the result would be 1 whi= ch has > >>>> changed the page flag. It isn't making sense to me. Why the page fla= g bit > >>>> is being fliped? > >>>> > >>>> When Anrdei had proposed these masks, they seemed like a fancy way o= f > >>>> filtering inside kernel and it was straight forward to understand. T= hese > >>>> masks would help his use cases for CRIU. So I'd included it. Please = can you > >>>> elaborate what is the purpose of negation? > >>> > >>> The XOR is a way to invert the tested value of a flag (from positive > >>> to negative and the other way) without having the API with invalid > >>> values (with required_flags and excluded_flags you need to define a > >>> rule about what happens if a flag is present in both of the masks - > >>> either prioritise one mask over the other or reject the call). > >> At minimum, one mask (required, any or excluded) must be specified. Fo= r a > >> page to get selected, the page flags must fulfill the criterion of all= the > >> specified masks. > > > > [Please see the comment below.] > > > > [...] > >> Lets translate words into table: > > [Yes, those tables captured the intent correctly.] > > > >>> BTW, I think I assumed that both conditions (all flags in > >>> required_flags and at least one in anyof_flags is present) need to be > >>> true for the page to be selected - is this your intention? > >> All the masks are optional. If all or any of the 3 masks are specified= , the > >> page flags must pass these masks to get selected. > > > > This explanation contradicts in part the introductory paragraph, but > > this version seems more useful as you can pass all masks zero to have > > all pages selected. > Sorry, I wrote it wrongly. (All the masks are not optional.) Let me > rephrase. All or at least any 1 of the 3 masks (required, any, exclude) > must be specified. The return_mask must always be specified. Error is > returned if all 3 masks (required, anyof, exclude) are zero or return_mas= k > is zero. Why do you need those restrictions? I'd guess it is valid to request a list of all pages with zero return_mask - this will return a compact list of used ranges of the virtual address space. > >> After taking a while to understand this and compare with already prese= nt > >> flag system, `negated flags` is comparatively difficult to understand = while > >> already present flags seem easier. > > > > Maybe replacing negated_flags in the API with matched_values =3D > > ~negated_flags would make this better? > > > > We compare having to understand XOR vs having to understand ordering > > of required_flags and excluded_flags. > There is no ordering in current masks scheme. No mask is preferable. For = a > page to get selected, all the definitions of the masks must be fulfilled. > You have come up with good example that what if required_mask =3D > exclude_mask. In this case, no page will fulfill the criterion and hence = no > page would be selected. It is user's fault that he isn't understanding th= e > definitions of these masks correctly. > > Now thinking about it, I can add a error check which would return error i= f > a bit in required and excluded masks matches. Would you like it? Lets put > this check in place. > (Previously I'd left it for user's wisdom not to do this. If he'll specif= y > same masks in them, he'll get no addresses out of the syscall.) This error case is (one of) the problems I propose avoiding. You also need much more text to describe the requred/excluded flags interactions and edge cases than saying that a flag must have a value equal to corresponding bit in ~negated_flags to be matched by requried/anyof masks. > > IOW my proposal is to replace branches in the masks interpretation (if > > in one set then matches but if in another set then doesn't; if flags > > match ... ) with plain calculation (flag is matching when equals > > ~negated_flags; if flags match the masks ...). Best Regards Micha=C5=82 Miros=C5=82aw