Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1606789rdb; Mon, 2 Oct 2023 15:16:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5bWBJvf15MxQUCBpKqtCPq5KbMH3buCtcCrefH0wN4/5rZEajqWIUKuiqE3L42LbzWAh3 X-Received: by 2002:a17:90a:f697:b0:277:298:deae with SMTP id cl23-20020a17090af69700b002770298deaemr10139815pjb.11.1696284993910; Mon, 02 Oct 2023 15:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696284993; cv=none; d=google.com; s=arc-20160816; b=FzK/XAO6F0JV4/+g158/iiy0f9E6Ocv539WdwFxONfXbfWHTiA+EuUjoxXbwT8stck g2MRyZRlJcpwhhsM/y/HQXufIeEgS1Z0YRnSTxixl6Xgi02QrlXHo4rwVzL/8PPyiuCZ ncAwjRknPeGPum36MCkD4FrgyCbO3jf/TzPLX1YgZ5dpHQHQH2Z5eLqO4qNrl+6uXljA 7Hssh8bXTisXLzhyNiQmB8Qw0EA11nfYL2P4Xq5esdtS/pQQ5xAlW5sPSSKyraqrWhb0 dBjb28ejQuLowwVZ8GM5CcYT/qMuxiXwSEUR+6pbk2K4QcBJFMCV0oEX5KKqwIzpTSzf 0G5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=4Pz/zszYZyE+z1VL1nxPoO+pF7/bzU2CO2PuRnZJXyI=; fh=2Eu1G32mlgI0m5bDvKevm1rawKoChy2uqT+hp9Zsybk=; b=UYRH8c5dNTPrxPTKSlvqaVnReGkys5ecbpVv7PJDnEF+0jOlMkxOpOuIOyio42+7SW ROVRH9A+5qMB8G0dN65Mqaa9s1b+91QUPgwNRXMbWwvJdnjtWltwGAdIrQ+sQ9Io4iFM dhcPAqHVAQEVUNWTKNayfcrnvXyC3icDMC0bChdr6dzMfqxRKVl9ghX8yz8od/Oq8B/V M5Z84FVCccIb3wA50Gye15iURtQX+5Ozt4xdUh5+ezQtrmWaP3u5JHR9t62mcqgDX9us JJuojvGCTvFw4NEbAComo4zo4Qcl9sLlupWY1CvxHkrU+UkZ6oz1FeOIGsL86KuSOp8C t4ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AvxWpVWw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l20-20020a17090aec1400b00277816efefasi8227062pjy.106.2023.10.02.15.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:16:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AvxWpVWw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 52A21823FAF8; Mon, 2 Oct 2023 12:34:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238881AbjJBTeS (ORCPT + 99 others); Mon, 2 Oct 2023 15:34:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238879AbjJBTeQ (ORCPT ); Mon, 2 Oct 2023 15:34:16 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD204D3 for ; Mon, 2 Oct 2023 12:34:12 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4053c6f0db8so1226135e9.3 for ; Mon, 02 Oct 2023 12:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696275251; x=1696880051; darn=vger.kernel.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=4Pz/zszYZyE+z1VL1nxPoO+pF7/bzU2CO2PuRnZJXyI=; b=AvxWpVWwDLsGAieXe1iULfVyuZN1Sv5x22bBYoK1E14jftZVMlKPTJ23l7zOVhUqM9 OhL7xjD8eSSs6idfaH6TJAr6FqCpfuSAIi5AiEzytrUkrXLL5NM5ps76QOWgFfzYYtd1 XC9xkmEDmVWXHW+4qY1xfwppHsTNgfTqFm3ipGsHAuqezUaRIwb68ajLsG0lR258vPCG VfxHCQBKlgEAw+UQXs0JGJJ4MyRT856a9Y/McYyQPf3NxTt7wXhZzvdue9r5Cgleo1VH ABHRDx8tw5iscMFhdf+kTN/9i+fosFHaaS6G3Tc5yDYBbsv7rIbL0QY8yKy5j5UH+q4d 2QBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696275251; x=1696880051; 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=4Pz/zszYZyE+z1VL1nxPoO+pF7/bzU2CO2PuRnZJXyI=; b=BxNlG8vaBsVGfDEpU3ns0C7cNrgg2V3WWOrOseOHWLao4Bf5BOUN9/D0DRPI6IEU+5 +ycdfkjOI4qqizJKQZDdRPe1ZdLQPTq92ye/h8/3xkHiH0LJV55MSYA87aQJPPa39E8B oe0J1duZYEnMQ/a7CNsdiE2MY2j9Q78TSpiqk4K/Mfsslt8XLlzfKNde93LIrR4LoLN8 V8eO/aVPX8X+gvwHysDd3atIe6/aMY5Q/mcBl+jsgS+QY+PzG14jJ9iT9wZZJc7OSqrG N+utdClZpdmL5cRJMaePT4XBYV2vRHSdjW/QxzoC0Dl05U1uYARCKrZ4QZ75lgXBkwJE fElA== X-Gm-Message-State: AOJu0Yz8u7J3IVgGMO+yhoYtX4I12gJFrMJ5o1+oOnykracQBAC6pT7L WC06oL6k0o7Z6P4gwu8MtXmR3fEXEJSnWft+EpaB4g== X-Received: by 2002:a05:6000:184:b0:31f:ea18:6f6b with SMTP id p4-20020a056000018400b0031fea186f6bmr10781947wrx.19.1696275250982; Mon, 02 Oct 2023 12:34:10 -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: <9434ef94-15e8-889c-0c31-3e875060a2f7@redhat.com> From: Lokesh Gidra Date: Mon, 2 Oct 2023 20:33:58 +0100 Message-ID: Subject: Re: [PATCH v2 2/3] userfaultfd: UFFDIO_REMAP uABI To: David Hildenbrand Cc: Peter Xu , Jann Horn , Suren Baghdasaryan , 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-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 12:34:24 -0700 (PDT) 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 wr= ote: > >>> > >>> On Mon, Oct 02, 2023 at 10:00:03AM +0200, David Hildenbrand wrote: > >>>> In case we cannot simply remap the page, the fallback sequence (from= the > >>>> cover letter) would be triggered. > >>>> > >>>> 1) UFFDIO_COPY > >>>> 2) MADV_DONTNEED > >>>> > >>>> So we would just handle the operation internally without a fallback. > >>> > >>> Note that I think there will be a slight difference on whole remap > >>> atomicity, on what happens if the page is modified after UFFDIO_COPY = but > >>> before DONTNEED. > >>> > >>> UFFDIO_REMAP guarantees full atomicity when moving the page, IOW, thr= eads > >>> can be updating the pages when ioctl(UFFDIO_REMAP), data won't get lo= st > >>> during movement, and it will generate a missing event after moved, wi= th > >>> latest data showing up on dest. > >>> > >>> I'm not sure that means such a fallback is a problem, Suren may know > >>> 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 the > >> 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. > [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 >