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 A4954C43334 for ; Wed, 15 Jun 2022 15:43:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A26D6B0071; Wed, 15 Jun 2022 11:43:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3526E6B0072; Wed, 15 Jun 2022 11:43:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21A196B0074; Wed, 15 Jun 2022 11:43:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0FFBF6B0071 for ; Wed, 15 Jun 2022 11:43:20 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id DCE2F60257 for ; Wed, 15 Jun 2022 15:43:19 +0000 (UTC) X-FDA: 79580889318.26.3422F5D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 670911A0092 for ; Wed, 15 Jun 2022 15:43:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655307798; 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=yDYQ6yfCWJES60ZRegN7DLxD2iOEtOMzNZaKefFOniM=; b=KyDRO4VENHpLvt2BSBi+O/SWO0H8Dor6TYNOaWSRqgVnzXoKC+l2UGnOEqohmiJsdDOVDF HEnsiduPEnY91p/H+NbtM+j78IbkLh9cAcFijblRGzMz57jAfiAGGcMmf6o2xRV04B3lMM MdmCe0qc6hkiAsyz5M/0Ds/Cge5U16c= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-459-K3wHP1O2NaajnxMaLHkiCg-1; Wed, 15 Jun 2022 11:43:18 -0400 X-MC-Unique: K3wHP1O2NaajnxMaLHkiCg-1 Received: by mail-il1-f199.google.com with SMTP id j18-20020a056e02219200b002d3aff22b4cso8628769ila.9 for ; Wed, 15 Jun 2022 08:43:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=yDYQ6yfCWJES60ZRegN7DLxD2iOEtOMzNZaKefFOniM=; b=nREEgs9ayDC/9E5gKoFFhg2I23WXH010Uwp0npyp6FGprPgjlNCUl08dZgXvsLwrNK BpIZHYvE/dYPSl8UrY2tXwqgkeW0OV3JCCs5uoHp1FMknojujW9+jolL6fld6LbpGIB7 OYUOIyRtZOFkxnjuX5NhHY+BcG4DymzFRreZvekTjnu+8aSQ7XgUUjz/KC7fNHQyLA6W 7VEmrvFCvhfO7AsdJvwgbFzj77ipuEpdE4UswGObu/Sqd3h1vMIpdidqI+bT9qd2T8Lj FsoeSpkoEPS7GHOGhNq8rh+OrurUbB2mhxIwri36nrN5fpwUDkwQ2SEibXwqWvuv9jN7 wkNA== X-Gm-Message-State: AJIora/YS5IIG1vhBZT9giWk2bBMHSBsqo7z1aKq6dBbY8gtQd8QcQGH gY2WkP2ysnxBjv8peJSH16q9q4ay8NGNuYzG0VdR2Ei7323Ttdw+Fg09sxqMiEub32GN5WfTfZS IT9yHueUeCsg= X-Received: by 2002:a05:6e02:1bc6:b0:2d3:dba7:f626 with SMTP id x6-20020a056e021bc600b002d3dba7f626mr239179ilv.299.1655307797089; Wed, 15 Jun 2022 08:43:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7LKLc4WyTkSCKitDbho3Xb5Jbn8DaDVJuq2fsTCZAVcDDiM38SFv49EYYcjYgMHFmQzt/Lw== X-Received: by 2002:a05:6e02:1bc6:b0:2d3:dba7:f626 with SMTP id x6-20020a056e021bc600b002d3dba7f626mr239164ilv.299.1655307796855; Wed, 15 Jun 2022 08:43:16 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id g63-20020a028545000000b0032e583132e4sm6291314jai.123.2022.06.15.08.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 08:43:16 -0700 (PDT) Date: Wed, 15 Jun 2022 11:43:14 -0400 From: Peter Xu To: Mike Rapoport Cc: Nadav Amit , John Hubbard , David Hildenbrand , Linux MM , Mike Kravetz , Hugh Dickins , Andrew Morton , Axel Rasmussen Subject: Re: [PATCH RFC] userfaultfd: introduce UFFDIO_COPY_MODE_YOUNG Message-ID: References: <20220613204043.98432-1-namit@vmware.com> <3eea2e6e-1646-546a-d9ef-d30052c00c7d@redhat.com> <481fc9d0-6122-bf59-9d04-23c10d256764@nvidia.com> <0BB58ACF-2801-4622-BF3B-9913A23AE46C@gmail.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655307799; a=rsa-sha256; cv=none; b=xUBSWvk1+DrVYdaFaias663PVW5bhzwKPM54ni/KnG/MKtx2Jwsle0+6CHb1QNQkkecjNt I7tNbpN9sEbp7wLXVHKYAtMqIdnIp50BnMZ/sd3e2arfXZ9njTHjZz5KViLJg+3OoJ13D7 QYyNbQiEkwXuBJnobTiQU0/D1xB5Y/o= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KyDRO4VE; spf=none (imf19.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655307799; 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=yDYQ6yfCWJES60ZRegN7DLxD2iOEtOMzNZaKefFOniM=; b=qXHXgH9yd3WArmYEDHA2JaLL5iwlC8MCboqBsNLXPMfi+j51Xnao6mqHk6WXEgungPWCnR Cy4wN9/gwW3ec/mFanHCRhOm1jDI/uIT/Q0oTVZ/3DIz4oYvMg1yXVOjuTM6aCxSuRLykN QF4ZB/TZfLVUzL9MswuKXu06TOmVPG8= X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 670911A0092 X-Stat-Signature: h7wkxo6qsfn6aogkk5pocb3ryiw377kk Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KyDRO4VE; spf=none (imf19.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1655307799-373162 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jun 15, 2022 at 10:26:21AM +0300, Mike Rapoport wrote: > On Tue, Jun 14, 2022 at 01:56:56PM -0700, Nadav Amit wrote: > > On Jun 14, 2022, at 1:40 PM, John Hubbard wrote: > > > > > On 6/14/22 11:56, Mike Rapoport wrote: > > >>> But, I cannot take it anymore: the list of arguments for uffd stuff is > > >>> crazy. I would like to collect all the possible arguments that are used for > > >>> uffd operation into some “struct uffd_op”. > > >> Squashing boolean parameters into int flags will also reduce the insane > > >> amount of parameters. No strong feelings though. > > >> > > > > > > Just a quick drive-by comment about boolean arguments: they ruin the > > > readability of the call sites. In practice, sometimes a single boolean > > > argument can be OK-ish (still poor to read at the call site, but easier > > > to code initially), but once you get past one boolean argument in the > > > function, readability is hopeless: > > > > > > foo(ptr, true, false, a == b); > > > > > > So if you have a choice, I implore you to prefer flags and/or enums. :) > > > > Thanks for the feedback - I am aware it is very confusing to have booleans > > and especially multiple ones in a func call. > > > > Just not sure how it maps to what I proposed. I thought of passing as an > > argument reference (pointer) to something similar to the following struct, > > which I think is very self-descriptive: > > > > struct uffd_op { > > /* various fields */ > > struct vm_area_struct *dst_vma; > > unsigned long len; > > atomic_t *mmap_changing; > > > > ... > > > > /* ... and some flags */ > > int wp: 1; > > int zero: 1; > > int read_likely: 1; > > > > ... > > }; > > > > I think that fits what you were asking for. The only thing I am not sure of, > > is whether to include in uffd_op fields that are internal to mm/userfaultfd > > such as “page” and “newly_allocated”. I guess not. > > mfill_atomic_install_pte() is called by shmem_mfill_atomic_pte() so it's > not entirely internal to mm/userfaultfd.c. > > Another thing is that with all the parameters packed into a struct, the > call sites could become really hairy, so maybe the best way would be to > pack some of the parameters and leave the others. > > But you'll never know until you try :) Yeh. Axel packed some booleans in f619147104c8e into mcopy_atomic_mode. The other option (besides uffd_ops) could be making mcopy_atomic_mode a bitmask and keep the rest, the mode itself only took 2 bits. uffd_ops sounds good too if the final outcome looks clean, since we do pass quite a few things over and over deep into the stack. Thanks, -- Peter Xu