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 A8382C43334 for ; Tue, 14 Jun 2022 17:14:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 182E26B0071; Tue, 14 Jun 2022 13:14:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 132276B0072; Tue, 14 Jun 2022 13:14:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F14B66B0073; Tue, 14 Jun 2022 13:14:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E17516B0071 for ; Tue, 14 Jun 2022 13:14:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9622B34885 for ; Tue, 14 Jun 2022 17:14:17 +0000 (UTC) X-FDA: 79577489754.12.6EAB2C3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id E81811C00B1 for ; Tue, 14 Jun 2022 17:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655226851; 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=z2M7olQSqGwA6OsTil4xsVRQg0ixmDk5nkTw65Myq+Y=; b=TpQSWPD+D5T44OZyqpGPGKzkLv4D8lPYxtdrtMhVFf9u1mFRBmFl4m8Tf12KOjlbi+7H9I qkqhKuKocC+bIsYc93z4LD1/nUcIp4jyMdtJfprlnOZaS7Cf1ytSvj7GM3iYjN5DoQJrBq 7Fjsx9KcAZ0wEhX55dLcKpXvQ4qquyE= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-vJxQ7n-UPHusPZ4y6DxM4g-1; Tue, 14 Jun 2022 13:14:09 -0400 X-MC-Unique: vJxQ7n-UPHusPZ4y6DxM4g-1 Received: by mail-wm1-f72.google.com with SMTP id p22-20020a05600c359600b0039c7b23a1c7so6773091wmq.2 for ; Tue, 14 Jun 2022 10:14:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=z2M7olQSqGwA6OsTil4xsVRQg0ixmDk5nkTw65Myq+Y=; b=THSLmWrQTltsVfhrDPcL1kx9/4ACDTohfNkq7CFyJTJKcF8o3DatJ7RJUbNWEpVomt dOxPBc4y/YibsIjXxZuLUXOV5pEN3UlRL7vzI94FTpNnKqcftYs4WStIlRvyVYnKdwnN OcbWwEDEiOrFL/ULcW6zagjKyJmBE0ItqSHJAa2GE4ZDuCUifxNeg8fzNEOHsy6smwRo B1GJTMGxoPb8OmYjpduWjwAzVDmvxPG6AL56/QuX35KqB3RS0e93g5k4YLGg+cnck5vW f0uOseTHZzJjAkyYROuEJYdU7j8rlbarpw2K4GIpE5oVVB3Af9GzEU+58uxd+xIFJYJS 8rqw== X-Gm-Message-State: AOAM532hdvfioLrVYf/Ln/SDSmz8WZ1qVWOg+wFMj+t+0O+shLKmQp8j tq9aN8QkJ4Q5+648mLGhToYrquKQGsLStwYG+KYTqEgm8IOLgmVnEesK8IegSDyy9Y3ixod6+ca 4NjY9X2KS8cM= X-Received: by 2002:a7b:c10d:0:b0:39c:4a17:1e90 with SMTP id w13-20020a7bc10d000000b0039c4a171e90mr5179122wmi.108.1655226848660; Tue, 14 Jun 2022 10:14:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBd29lNRlHwIYn8bQ/zsTKCUhx9j9wqzTIMFkY6jLCb0VMXABEV2HgKoMzesUG0IZbcktjOQ== X-Received: by 2002:a7b:c10d:0:b0:39c:4a17:1e90 with SMTP id w13-20020a7bc10d000000b0039c4a171e90mr5179104wmi.108.1655226848416; Tue, 14 Jun 2022 10:14:08 -0700 (PDT) Received: from ?IPV6:2003:cb:c70b:cf00:aace:de16:d459:d411? (p200300cbc70bcf00aacede16d459d411.dip0.t-ipconnect.de. [2003:cb:c70b:cf00:aace:de16:d459:d411]) by smtp.gmail.com with ESMTPSA id p190-20020a1c29c7000000b00397402ae674sm17751509wmp.11.2022.06.14.10.14.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jun 2022 10:14:07 -0700 (PDT) Message-ID: Date: Tue, 14 Jun 2022 19:14:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: Nadav Amit Cc: Peter Xu , Linux MM , Mike Kravetz , Hugh Dickins , Andrew Morton , Axel Rasmussen , Mike Rapoport References: <20220613204043.98432-1-namit@vmware.com> <3eea2e6e-1646-546a-d9ef-d30052c00c7d@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH RFC] userfaultfd: introduce UFFDIO_COPY_MODE_YOUNG In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TpQSWPD+; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf21.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655226857; 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=z2M7olQSqGwA6OsTil4xsVRQg0ixmDk5nkTw65Myq+Y=; b=NSC79eFXkUuPUYn75scfJ3yZYWac1JOAYD8FX1ZAl4YY005btnvrydySGFSVmYwMv4KJNU Zi16GUElJUh4sROBk3clz314p3nowA2c4sOwljPhDlafnIjgbPSEMdfkqO4T1AxMYt9cEC FI3ND69TqPVDI0n66Iwzm88RZOAEfQ4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655226857; a=rsa-sha256; cv=none; b=pFiAsTt/s5YZBW/ICKOrStB5fA7y1mhUVnrck/KxIByJfp+PcaHpKxV/AKltlkeuFcirH2 lnpErJQ35BnFPGUawm2ppSfYM298bMkS/GnBGKpYr+sjhJ5e2HCSrKtIQobwHys+ITNs8M MITIOMaKIxw4TwVSOu7emyTIVjBn470= X-Stat-Signature: bm8sqyh7q9rjodcun3ie3pjhgxye4fwe X-Rspamd-Queue-Id: E81811C00B1 X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TpQSWPD+; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf21.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam10 X-HE-Tag: 1655226856-797314 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: [...] >> I'm bad at naming, UFFDIO_COPY_MODE_ACCESS_LIKELY would express what I >> have in mind. > > How about UFFDIO_COPY_MODE_WILLNEED_READ ? Would work for me. > >> >>> Introduce UFFDIO_COPY_MODE_YOUNG to enable userspace to request the >>> young bit to be set. For UFFDIO_CONTINUE and UFFDIO_ZEROPAGE set the bit >>> unconditionally since the former is only used to resolve page-faults and >>> the latter would not benefit from not setting the access-bit. >>> >>> Cc: Mike Kravetz >>> Cc: Hugh Dickins >>> Cc: Andrew Morton >>> Cc: Axel Rasmussen >>> Cc: Peter Xu >>> Cc: David Hildenbrand >>> Cc: Mike Rapoport >>> Signed-off-by: Nadav Amit >>> >>> --- >>> >>> There are 2 possible enhancements: >>> >>> 1. Use the flag to decide on whether to mark the PTE as dirty (for >>> writable PTEs). I guess that setting the dirty-bit is as expensive as >>> setting the access-bit, and setting it introduces similar tradeoffs, >>> as mentioned above. >>> >>> 2. Introduce a similar mode for write-protect and use this information >>> for setting both the young and dirty bits. Makes one wonder whether >>> mprotect() should also set the bit in certain cases... >> >> I wonder if UFFDIO_COPY_MODE_READ_ACCESS_LIKELY vs. >> UFFDIO_COPY_WRITE_ACCESS_LIKELY could evenmake sense. I feel like it could. >> >> For example, QEMU knows if a page fault it's resolving was due to a read >> or a write fault and could use that information accordingly. Of course, >> we don't completely know if we currently have a read fault, if we could >> get a write fault immediately after. >> >> Especially in the context of UFFDIO_ZEROPAGE, >> UFFDIO_ZEROPAGE_WRITE_ACCESS_LIKELY could ... not place the zeropage but >> instead populate an actual page and mark it accessed+dirty. I even have >> a use case for that ;) >> >> >> The kernel could decide how to treat these hints -- for example, if it >> doesn't want user space to mess with access/dirty bits, it could just >> mostly ignore the hints. > > I can do that. I think users can do the zero page-copy themselves today, but > whatever you prefer. Just so we're on the same page and I'm not missing some smart way: it would have to provide a zeroed buffer in user space, and trigger the copy via UFFDIO_COPY. Instead, the kernel can simply clear the user page directly when allocating from the buddy, instead of eventually zeroing it and then copying from a zeroed user buffer / zeropage. > > 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”. > > Any objection? Not from my side, as long as it doesn't break uapi. -- Thanks, David / dhildenb