Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1597293rdb; Mon, 2 Oct 2023 14:58:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqyMtTjlT0uuTBU2xuhVU52BEhvDp0al3iQeWVOeENlt8c9SAuJkr21h4QCAqWMm8YUGll X-Received: by 2002:a05:6a20:cea5:b0:13f:8153:7e31 with SMTP id if37-20020a056a20cea500b0013f81537e31mr9851183pzb.20.1696283883727; Mon, 02 Oct 2023 14:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696283883; cv=none; d=google.com; s=arc-20160816; b=D83922nB7c/7FBO7Z5LIY2ciXCwluOPzt7kPNh4jah3z0je+b9Zes/nWlt5q7Uah+x eNWl3dA/6DBJgbN6mgbqHpmzRgWU8CUT1ww197e5fmvEzBOLM46QfMgGGdzObHdYGMKt yBo/sGTUWuEuBkHQ26Q7BTxC+nP3lx3w+dLXeG+SJ4seDSKyOtcQ1F+6QNF5xDYiHOt9 LYRAdKHHwjlcLzU4P6k1PhXg2tzoEPTx9v5BHgC8ACjKZpCsufkP98/GHb5XViZzGbh2 vl3kPR9Wm2YHWUaSlnG47Dt8DIK6ZIbHwi8cLxZhaR7rCSkHFaMoMR0HmAdEXymjEI1R KcAA== 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:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=wp+uBb3vd++p/TELNcrTFrgdStWMZDT1c1gwMgRnAb0=; fh=QY7DYvNpX7D70LTEtIOTETr2WhrytYbBqcbuztoLF5M=; b=zvP++wCAnp8W/hfYDn0zTnKc9M+bP2ho/DW8lgSpVPLKHlm0qnt4DYOLtDtScgneFF Xuxrsc8Z6ZdrE7uoTRwKHDAsq04LDtUZ1LGL585IgsYIySAuhF14Sw4psX+oTtwOiHa3 2ueJvFiIfYbXKYrxanF/DnA2ix4CMXB0FXjlf+jOq5NakIvUI4WHxvPc0UwrC3iWVJUb bjRfA80XHj66r+Ob8STF0QLpKYQuiplI/Sc7ZqtMhOTJcQFaRm9NoORTIu8CkQC46H4/ zXOMh+ogbXYIbTCOvMAoUdYtu6D2zFVGgFi8U9CNt6IajsiT7lN6BE4x41BCSFMXc6dy niBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PRnD0d77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id t20-20020a170902d29400b001c74876f029si7554977plc.381.2023.10.02.14.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 14:58:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PRnD0d77; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3B00480A164A; Mon, 2 Oct 2023 10:44:30 -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 S229463AbjJBRoV (ORCPT + 99 others); Mon, 2 Oct 2023 13:44:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbjJBRoT (ORCPT ); Mon, 2 Oct 2023 13:44:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10BAFAC for ; Mon, 2 Oct 2023 10:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696268609; 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=wp+uBb3vd++p/TELNcrTFrgdStWMZDT1c1gwMgRnAb0=; b=PRnD0d77mXz1UpQ7+H07YQa7ALwYdjwQTddnfYoYPn2kv+/LU6CrZdGcL7v2oXiE7iUsB4 pH0jznBlVykXlfURc85uqoxIXr7vtvTIGE3642RJ6tmOteMpJEYZIn4Y1vlqQU9QlUz2/T zF8daEc3Fr3GWLMJfL9aRUnFE2HwSgI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-Vmi1npfOM-OGNW9LFHDtuQ-1; Mon, 02 Oct 2023 13:43:18 -0400 X-MC-Unique: Vmi1npfOM-OGNW9LFHDtuQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3232c3df248so33416f8f.3 for ; Mon, 02 Oct 2023 10:43:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696268597; x=1696873397; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wp+uBb3vd++p/TELNcrTFrgdStWMZDT1c1gwMgRnAb0=; b=AUJPMmfgvXhuM20Cxq6a88eUwStlCs7s5nSZuwZTg0bOs10r+5tVLZHbjfhpKwpyOa olp66RM3Lh9DgZCr0oTcn3C5nUbKKJnZMw8LaEj1adcJYZ+ekzqi01YKuIS8WDSYmqDu hbhezviDIaPLcQWMjxMjSHfNdzRrvxXmUyZY9aJIIdqdFzcFEM7JCGa9t49uH/xP+pCs eVivbR3negwKwU/31vid8+WXZ1RmdcVF+SV8dv+t3VgQOmHyW8BGm42CzZyCaX6sfIT2 nWgvDmLnmoxoymeohANXfN0FmGBP5fm86der7e1SR+9DujrZm5CSdkfw36Bkcnu4PMnA xqDQ== X-Gm-Message-State: AOJu0YzOgcSGyayBas6M8VYZj1lYxK/LUaYpkgJdXLOFK3aMz6f3Uqa7 NIgU58YDUcn56IRv4UedBJcrSRGWBkesur69gkJ50ag580aY7JWzk7q6UJXSa75W5v9CiY583jt 1ndBaDl6RgO0+DyRzJQSCJadu X-Received: by 2002:a5d:6306:0:b0:31f:eed7:2fdc with SMTP id i6-20020a5d6306000000b0031feed72fdcmr9669349wru.35.1696268596934; Mon, 02 Oct 2023 10:43:16 -0700 (PDT) X-Received: by 2002:a5d:6306:0:b0:31f:eed7:2fdc with SMTP id i6-20020a5d6306000000b0031feed72fdcmr9669316wru.35.1696268596482; Mon, 02 Oct 2023 10:43:16 -0700 (PDT) Received: from ?IPV6:2003:cb:c735:f200:cb49:cb8f:88fc:9446? (p200300cbc735f200cb49cb8f88fc9446.dip0.t-ipconnect.de. [2003:cb:c735:f200:cb49:cb8f:88fc:9446]) by smtp.gmail.com with ESMTPSA id m12-20020a056000174c00b003233b554e6esm14288618wrf.85.2023.10.02.10.43.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Oct 2023 10:43:16 -0700 (PDT) Message-ID: <9434ef94-15e8-889c-0c31-3e875060a2f7@redhat.com> Date: Mon, 2 Oct 2023 19:43:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: Lokesh Gidra , Peter Xu Cc: 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 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> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 2/3] userfaultfd: UFFDIO_REMAP uABI In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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 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 10:44:30 -0700 (PDT) On 02.10.23 17:55, Lokesh Gidra wrote: > On Mon, Oct 2, 2023 at 4:46 PM Lokesh Gidra wrote: >> >> On Mon, Oct 2, 2023 at 4:21 PM 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 (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, threads >>> 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 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. [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