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 1208CE748FE for ; Mon, 2 Oct 2023 17:43:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F4FE8D004D; Mon, 2 Oct 2023 13:43:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77C858D000E; Mon, 2 Oct 2023 13:43:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CF978D004D; Mon, 2 Oct 2023 13:43:27 -0400 (EDT) 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 4668A8D000E for ; Mon, 2 Oct 2023 13:43:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1FE141CA18C for ; Mon, 2 Oct 2023 17:43:27 +0000 (UTC) X-FDA: 81301243254.24.30126CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id E924540012 for ; Mon, 2 Oct 2023 17:43:24 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UMyHeMEN; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696268605; a=rsa-sha256; cv=none; b=QJQx7amSaykTAZNMfRZ3qRoU03J6v3vqd6DgK4dC3IILRfxUqlxBwOLOi6tB8ciAJ6LLhO RNyaYYKvpGr28JPxa/I9deBBLLeXJfx608g2eyXKW0rJ6YQ0cEpaUURha0QwxcyGMkWk93 jtN+MLBD7qsCoUyjYA/Lg3kP85BNclw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UMyHeMEN; spf=pass (imf17.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@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=1696268605; 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=wp+uBb3vd++p/TELNcrTFrgdStWMZDT1c1gwMgRnAb0=; b=rkgCa34kq5CUZvTpAcAbf4Hvn2+qW6gw2zgj/GgWOdo5JLeTiOTg6feaQpHt1bXQNNhRvj qRgYQtcNgAOKBVACQFZxDAnK2B+eH3DqVpxlvUMScBIn70H3r64Ue/ZqoBTfI13p4OJrui ekLxrNVfF7caHWVzUQFlBi59jhghVHs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696268604; 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=UMyHeMENE/sD/HigQQvLRhqXyG1azOksexljv6Luh7YmalcYSCEn5STY4pF/IJ7qC2vFZB Uz+0uz1mb1KYX2k4bqJm2jydx8Bur77Aq411uJS949BoE7snD4VrdrJsrly1NAT0WXLuW9 pFpgdhN2hR8HQvGfsSykEcSMJQmPlNc= 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-196-ePKDWwHlMTqQxjBgYIx2Mg-1; Mon, 02 Oct 2023 13:43:18 -0400 X-MC-Unique: ePKDWwHlMTqQxjBgYIx2Mg-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3248ebee5f4so34287f8f.2 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=IsfIXLiBTGS2b7iCi2Gax2hcvGo+qcGokk5Nwk+nOlhzXvp7h+yB2OhgV6IfzTFJko N6S10L4GLqIkizIBKKJv0i4mY7iSEkoBxb8jfJQn7vIyVOACV8zWTUxPuHsTjrEyliXS fAbexok59wIF80WplPuFVlRdlCUlzofoeVc+G8Ydf70NQnKBFP+3AObqvf9oXyTjEsH1 s92+Siemxp55oJENoiBXnpnm9i7t5prg/Svmxu7kpHtCOpijpmK7zxgb1hBlnOBxmM+f 0ko4Pzk5nSkcgiEaQ76h1e/SnnhWQTEtDE1h9dnmPfKCENUxaWrM4/qRschhJTLowm2j LaLQ== X-Gm-Message-State: AOJu0YxQ7ROd+sHegnve3IJ3LXv7FwFO5ZPdtaKVWJ+4ICnTVHBkGF3K OQOePoA+UE8BxUT2Dv/DOYs5KKsxxFEjJr+OymkGmmw5OAKLtKBVZhpouqIm0d+ryVFAvtGwzdf 3mIqBnmmh+us= X-Received: by 2002:a5d:6306:0:b0:31f:eed7:2fdc with SMTP id i6-20020a5d6306000000b0031feed72fdcmr9669345wru.35.1696268596931; Mon, 02 Oct 2023 10:43:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlnYfzZHHUMm6vDazX7X6pg+Hfr/KO2FNcqHXBe1PdnVdfBy7vPvSIlNwDZzVhMT/U34rc2w== 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 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: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E924540012 X-Stat-Signature: 7taas7wit3oyyou6kepzbnqd1xe9tbjj X-Rspam-User: X-HE-Tag: 1696268604-447758 X-HE-Meta: U2FsdGVkX19HiRL8Fxy2FhCLeMDIJro/NmvRMArGrR2aehdQvuC6hm6eq3fkIy9DBhtIeR+0pS8Mpqpx0/Gv5mtCV6fu4RcnBe+Ej8DkCWPo2SBAccen58XozhBGrAhtZmzr5/0fEY85VhYgQeRv6rLTbkrJZ4fsI6MiDmOS8N8JkYPv7wtKUQ4I5N1de4UElruv0GWNh2BOWHVPAuqcTv4ZRDn9cuWsi3SkLaAK/p/wYZwWnEM+c3cAsyksAPoEwZlC04/sgpOf13mf0Z+7sEWtUddG7/olgRcD2Dtlh5HUXrk2/BEYaDW+Y5Ik+hfNSJOYVc9izi+25tchRVUPsSXASiDJ25f/UaAydoQy+wVOjYZ5eMe0XqekOMpdr0HXK/K9hA1kGk47AUQP4Kn1lCJZWlz8gY4SY1LoBsZaRSPts94fPEmlSwFa6S73t+qNdZQ82pa00tlZl8C3v1FBKz644aUtFa0b1iKOey+gWvTNSu2IXuORLQsbRvUVFQphEQAom8RB7YhcwpcAUt6jYTgmp+v5dIXK6xN2P06roB1zEzy4RnaZNf5LQZFx8KEKtI9rFXXc+jWaaUw+EA1B+FtOuGzgH2kz2MJX5yQGDCgXETXxWOl71GyddsNKKyKXKuuj5moS285xI/y5RlMl9TwZP6ZL74ZqI9bKDyAeP1EtxOO/w74f6iJvkYNAuKQZtuux+hHSlSYDA6DBFtrn57OjDB3UPvNgYlUwm7tDZvbn7K8BvbCFJLd780Yh2wAx+K6Z7r8i9cWshdNKmYcGpt4Xt29ErRylVDDSwKFFq483vq/YGEzPNCcTNpRYXWHmti4jla07jqXKmiOPaGL/TmqJBzTgxHhWmy6ZU9WOypTEwpE5aGOjsWXcPqdpqNKe7BKfMb2kkOAz1qYcqw9JSVlgCbqdsfxMXU7m7hZvbSKFgPZ4YOZK39bvhp1yriTY/XlfU1Rcgr6JJnWSH72 /kIcmkgg ClVMjTacld6SQI0M8LyMtf6Ra34p8R6AH/fnS7H9lhb1KZSOfun2kql2ix96DlBKdwJFYIOQyMfEbbDZFJl/+hbO4bQfqyp/VFRwKN4BZFoUusxbCzZAk5Lo+PgiMkd530msPHHA2EDVydomCCgsGKPwp0W3S1E+jW6HoMeaZqcTK/TO1U+DrxPmXlylRqXYTAGR14qx0DYf8cFhvhuJuINTdlPxxG1KqtV2cw71H1qq4L2gfZ3QfN6KKZqR2BJzozcjsCbZzdcZwxvj/0erGLuE5lBW+RJ2ZzqeXjp0NUobFERbtF0ZLjEtEyQIt9FPNPcNZgO28rOQPSsbPZ0nGSA5OzWlyDOuA5jUNUgV2Pby2EvdD6fvxtvS8ZdwqCbIBlwsdwjqyMQsHF1JOj6chDUugdXuExjbGHwDS5ePk0NqIM1pskpii81qNo6HAa73lPu2hbLLsh0dihWZGa+2DjTWx/+mUKv2AF4+H 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 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