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 8ED52E8FDB0 for ; Tue, 3 Oct 2023 20:04:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16BA66B0168; Tue, 3 Oct 2023 16:04:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 11BF46B0169; Tue, 3 Oct 2023 16:04:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFF5E6B016B; Tue, 3 Oct 2023 16:04:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E09156B0168 for ; Tue, 3 Oct 2023 16:04:58 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B81BA8044C for ; Tue, 3 Oct 2023 20:04:58 +0000 (UTC) X-FDA: 81305228676.11.01230B0 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) by imf06.hostedemail.com (Postfix) with ESMTP id C1BE8180002 for ; Tue, 3 Oct 2023 20:04:56 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=iUPD7Vwg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of surenb@google.com designates 209.85.128.175 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696363496; 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=T4HnvVJM5UhNryBKAzUQ7ExKjrQO05hotZm+y3hVwo0=; b=KIxwHRAkEcFTK+IobZ9RpODTQfLAaU1YZsosUe3aqZmnfzgnpxfziSrhZqLgj5lEAgP+kx 32HTbAOFeMjGhBV4cMW4dJTTCuvhI2X+EvMv5ZxebC6N/Y9EyRtFwjbxN63T885DhtGgjH 62pN2Q1d5ch9FBz1/lB4bWYvHvS5bjc= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=iUPD7Vwg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of surenb@google.com designates 209.85.128.175 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696363496; a=rsa-sha256; cv=none; b=zqdbUdot35Dw4tnBOLdRBc/0IiJgNmtORKA08Oy3MOgJv8GMl6Db33f1pJRyY3v9y6YQpB ZhsGrFohis/tnhTo7qIArq0fYd+Kbd4H8SgVwJATDgr/tVJeXjcxboAZZaIigPtaizJFIr yf5/PVlJhR+rjEfafm91B874RL/mfos= Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-5a4c073cc06so1745867b3.1 for ; Tue, 03 Oct 2023 13:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696363496; x=1696968296; darn=kvack.org; 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=T4HnvVJM5UhNryBKAzUQ7ExKjrQO05hotZm+y3hVwo0=; b=iUPD7Vwgjmm3R36l8onu0h9MTn1tDf+W5x9IfsZ0T4bD+8N1SXJbElcDhOjmPs2sOM 2KoO8krmUYypxuSLPHr68ugD5lQMammJwW5j9TxQzp5Rt6CHkfTGA4jwbpK7Xrr65sOT 27VTmYx3jV3EKyVX9AOupQ8axJJ/U7QXnjmmOoVhj6YOaCcieAdRpaF5vXsmJ6BzrfyL Ht40hJzckraMZAI69KgnCwIns+eRmBHWA0Ioo4F091FSEudfYEq3S4p/sHiKsClWT4SZ ISjMf3BGrTPhoj/GPp8pc7N1pOqHa1HDWSpfMyjUW35PHxRCiMqy6xR5Yh67358eEWYs eSXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696363496; x=1696968296; 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=T4HnvVJM5UhNryBKAzUQ7ExKjrQO05hotZm+y3hVwo0=; b=MY3tfnFhktNIJSaCf82MFXmnuD0GZ+5g8uynWYlO0pFPzan6kw0veG4wEOEnMV9nIU TM9UHynUd+WUlsh3JXD/2eHAZcBxUCm1fJjP3YgxCXQM+QcXz/Ap2fW9rcKNr4fk4b73 esR8wcGdM9BFSNTUlIHhY6FYJYpabX7rONKosXPtCfCWsaX+YV7Ih2thTpTRm930JDN+ evetP0Q/gL0xR2q1ZJAFbFgz5RAiJYuOZzHCHRklO/qLVaOHVUoY9CGEX6hbDa7VIx0L S9HFqkEA0WqqhRxr5WCfbPBsAkbF0TGIwDMAiyr+e7Ckjba1QlOS9B4YwkTtYvE4UzaK VnOA== X-Gm-Message-State: AOJu0YwWC12rLGIQUxIhMJYb9u0pkS9RhCO8ACPklmLvAsLAw8zrq4iZ bvqYhwb5pY1f9AIHqpfO+q1Kg8HXR3UUWaV/h8rERQ== X-Google-Smtp-Source: AGHT+IH9yT6ckHnJBiB5Cfo13hxaaAKxy5AR7WcWqkiDMh30P5bHjEM+Bte/4PVXH+TW9h5J6PjpHuiA2d0kgiAUOWA= X-Received: by 2002:a0d:d546:0:b0:583:9935:b8ba with SMTP id x67-20020a0dd546000000b005839935b8bamr2961777ywd.6.1696363495623; Tue, 03 Oct 2023 13:04:55 -0700 (PDT) MIME-Version: 1.0 References: <20230923013148.1390521-1-surenb@google.com> <20230923013148.1390521-3-surenb@google.com> <03f95e90-82bd-6ee2-7c0d-d4dc5d3e15ee@redhat.com> <98b21e78-a90d-8b54-3659-e9b890be094f@redhat.com> <85e5390c-660c-ef9e-b415-00ee71bc5cbf@redhat.com> <9434ef94-15e8-889c-0c31-3e875060a2f7@redhat.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 3 Oct 2023 13:04:44 -0700 Message-ID: Subject: Re: [PATCH v2 2/3] userfaultfd: UFFDIO_REMAP uABI To: Lokesh Gidra Cc: David Hildenbrand , Peter Xu , Jann Horn , akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com, zhangpeng362@huawei.com, bgeffon@google.com, kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C1BE8180002 X-Stat-Signature: xg15x3joyixd3fgrreqnopu5t9jct8dr X-Rspam-User: X-HE-Tag: 1696363496-566890 X-HE-Meta: U2FsdGVkX19ukRVkyQOUHC2e4P6U50eDGDnc/vmNT/volKSlCCMGbxFvnMHaWjgF4enJkDbaqBmPI7Ccq/wqE4BfC2hJox/axNaK8skVyi0qFc1C95MxUEFfxeCSldmDU7CW2bIB9qszTUubasVgJXB+loRL1elOECdeowRbFaOqqk13DIMW2iLND30yl8L+yWNMGplZqbm8L9QHe9S+VAIWRfs9MTXRsXLSMD6z1ga5v37SGwXOA/Il4vfY1NFK6Z9QdwsheGo8NLb2CMWyMqyW8sNcD8Tuaw5W2RuTqGkxOprcJDHnagiks7M3J3nmqtx3oE4AKQwHX8H1KIWoPk7/Hs+O9fQ8fm+cbuGHRTJZQjwt15E5TRInzs3wAGj6zzwBOkI+aE0+H/IAGkkdsHZlHHRaB+j3ovHooJ75U2Y0mRAOECU4iHN5PKZxi/W8GSSb/48MfbDVwHGD0+BMELdUuAD5duKf4jDW2xge1NZphB66enLNzJVGnUq6IfW3Rb3fU+S4KPURU8AMBzkbWvLfpLitNaDDNa+/7g1EY6jhnyxybk5deQtUV0AOTb7SU8G4PAnACGe5nUDyoNDkOIsYhUMuSrhjfhC7pM5hiWZCLU1771GaMYSgPrJgaihVCF8fGGJzyS/yWFlEgzoAwolFJLNdseicFaNL24DjtwS2nTI8n3bQvZodH6/xzLpMTa71FlormH/0cw9dkJLtDKVahze8x3prZjf4j+4gSH1S61HVQik3mT+2evuxz+w5AYb2CcFgIjRlmKl31k6Qb/SK2oBUKXtJ7C2HcYrfVH/f+TFxF8TxKSe3h+K2Lmp5TW+Avh6skHTmR6BSJqjKeUhTksE5JQt+itHdHEftMl39dmOkmzt7Iknj12XpY5fLY80P631ePuWSjwQ2Si0l3S8TuZFGsJCgnmKGKfz31umH2GBanoUfJqO4X5PoR4SlVG1BJt54H/KMv/4NEBK xNPeS/he 8UYmS4MaMz6+FGsBtzMxPc+KNW5LrDi9tbjWe2FhHX1PqW4fFhN7k9JEPZnqK0mXlYtfLCGU6xGeh8XspTd9YHTJILwP6MZyJN1QlLzM+FIhuxQ30pXifw2p98pkgnFo2//zNAufHGqdi+xIBAJpxE4JjLVliL+btT4SalHzfaES4Aq9KG6oLBXOdmxvYkvl6INUz4Pby7FQOUtYx5RY44cv1HOyOiTcTO4JOFUt/l+S8ACBKILbG3UvbUrdoZIMtFxmZwlaKNjmzXJi/aTHPoRxgETvEDRL/b2q/SZbk+kkjKaftdwCtnVzMn3PlhEKjIY5LSMPrMZqgb3k= 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 Mon, Oct 2, 2023 at 12:34=E2=80=AFPM Lokesh Gidra wrote: > > On Mon, Oct 2, 2023 at 6:43=E2=80=AFPM David Hildenbrand wrote: > > > > On 02.10.23 17:55, Lokesh Gidra wrote: > > > On Mon, Oct 2, 2023 at 4:46=E2=80=AFPM Lokesh Gidra wrote: > > >> > > >> On Mon, Oct 2, 2023 at 4:21=E2=80=AFPM Peter Xu = wrote: > > >>> > > >>> On Mon, Oct 02, 2023 at 10:00:03AM +0200, David Hildenbrand wrote: > > >>>> In case we cannot simply remap the page, the fallback sequence (fr= om the > > >>>> cover letter) would be triggered. > > >>>> > > >>>> 1) UFFDIO_COPY > > >>>> 2) MADV_DONTNEED > > >>>> > > >>>> So we would just handle the operation internally without a fallbac= k. > > >>> > > >>> Note that I think there will be a slight difference on whole remap > > >>> atomicity, on what happens if the page is modified after UFFDIO_COP= Y but > > >>> before DONTNEED. > > >>> > > >>> UFFDIO_REMAP guarantees full atomicity when moving the page, IOW, t= hreads > > >>> can be updating the pages when ioctl(UFFDIO_REMAP), data won't get = lost > > >>> during movement, and it will generate a missing event after moved, = with > > >>> latest data showing up on dest. > > >>> > > >>> I'm not sure that means such a fallback is a problem, Suren may kno= w > > >>> better with the use case. > > >> > > >> Although there is no problem in using fallback with our use case but > > >> as a user of userfaultfd, I'd suggest leaving it to the developer. > > >> Failing with appropriate errno makes more sense. If handled in the > > >> kernel, then the user may assume at the end of the operation that th= e > > >> src vma is completely unmapped. And if not correctness issues, it > > >> could lead to memory leaks. > > > > > > I meant that in addition to the possibility of correctness issues due > > > to lack of atomicity, it could also lead to memory leaks, as the user > > > may assume that src vma is empty post-operation. IMHO, it's better to > > > fail with errno so that the user would fix the code with necessary > > > changes (like using DONTFORK, if forking). > > > > Leaving the atomicity discussion out because I think this can just be > > handled (e.g., the src_vma would always be empty post-operation): > > > > It might not necessarily be a good idea to only expose micro-operations > > to user space. If the user-space fallback will almost always be > > "UFFDIO_COPY+MADV_DONTNEED", then clearly the logical operation > > performed is moving data, ideally with zero-copy. > > > IMHO, such a fallback will be useful only if it's possible that only > some pages in the src vma fail due to this. But even then it would be > really useful to have a flag maybe like UFFDIO_REMAP_FALLBACK_COPY to > control if the user wants the fallback or not. OTOH, if this is > something that can be detected for the entire src vma, then failing > with errno is more appropriate. > > Given that the patch is already quite complicated, I humbly suggest > leaving the fallback for now as a TODO. Ok, I think it makes sense to implement the strict remap logic but in a way that we can easily add copy fallback if that's needed in the future. So, I'll change UFFDIO_REMAP to UFFDIO_MOVE and will return some unique error, like EBUSY when the page is not PAE. If we need to add a copy fallback in the future, we will add a UFFDIO_MOVE_MODE_ALLOW_COPY flag and will implement the copy mechanism. Does that sound good? > > > [as said as reply to Peter, one could still have magic flags for users > > that really want to detect when zero-copy is impossible] > > > > With a logical MOVE API users like compaction [as given in the cover > > letter], not every such user has to eventually implement fallback paths= . > > > > But just my 2 cents, the UFFDIO_REMAP users probably can share what the > > exact use cases are and if fallbacks are required at all or if no-KSM + > > DONTFORK just does the trick. > > > > -- > > Cheers, > > > > David / dhildenb > >