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 E4568CE7AFC for ; Thu, 28 Sep 2023 17:51:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 521938D00CC; Thu, 28 Sep 2023 13:51:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D1EE8D0053; Thu, 28 Sep 2023 13:51:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 372708D00CC; Thu, 28 Sep 2023 13:51:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2933A8D0053 for ; Thu, 28 Sep 2023 13:51:28 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F2DD5120451 for ; Thu, 28 Sep 2023 17:51:27 +0000 (UTC) X-FDA: 81286748214.10.6081D8F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id A9B97140022 for ; Thu, 28 Sep 2023 17:51:25 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NA8mj8bX; spf=pass (imf26.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=1695923485; 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=95cgsBpE/c9mQyni+eRrbJAAJxH4nZT5sQdvz0Yfag8=; b=aiDa1BytmTDOXUkFrMMqKAdMEVERGMKthfHH+RsXcztDf/7OWWYpPNpZWuPX0y4vEOYbDj IE9/O+CZpZTfic9aHCDM2GcuPxw4ednkf9aYVnI6SbdC4OOCbuBp+WST7kfwwXiwtGvhAN DgHbPvTZoWfyaneO7kzQJcFqgxqc/2M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695923485; a=rsa-sha256; cv=none; b=dirIIhOHI4vnqPgcwmw2/hFmtA67MWRI115lnmk6OFdjPFKXDRoO+KAYVlQwllVRIQk+hL iF2tsMJ/qcz2xXh3CK07wTtOz3vmupob2rrQJbwxjqXSFM/FpSTNprp2MtnFH+jOLEezJn 16q+Cl9Vgk7RYiWEAJ+fC+MAv0G2c+g= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NA8mj8bX; spf=pass (imf26.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695923485; 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=95cgsBpE/c9mQyni+eRrbJAAJxH4nZT5sQdvz0Yfag8=; b=NA8mj8bXwty4CnZ/Y40/nwoydaie9Vlwc74FrkZhLFrk+U+Y9d9y/00/KU9Td57tXooCpD e/zu0+aceXl7eeIwH2gDN3mh7EIWALwegVn9oeJehd3P0oKwIvkOAJF/7fCYtR9fMuZgv5 DX7YAq5P4uSCBXb5CB96WIplnNRF/lU= 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-684-D-nJadMaM322_qtxiLkudQ-1; Thu, 28 Sep 2023 13:51:22 -0400 X-MC-Unique: D-nJadMaM322_qtxiLkudQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3247f646affso1386141f8f.1 for ; Thu, 28 Sep 2023 10:51:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695923481; x=1696528281; 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=95cgsBpE/c9mQyni+eRrbJAAJxH4nZT5sQdvz0Yfag8=; b=Cf+SF8Dn1u//33Rv/LV0280XJVwHYVKuX163bnR9seQOYS7DAuWdJdKyIYVnj/d9HG 5oh9KHC52CA8R2Ng5ThopVIhnugSJke3V0i5Xhu+lNqZDD2YYRTXJ8icVr46LhlT/08b ANVxn0LpMhqRJN8vgW7t8shmlZJ4bgerzATgsLWJUicuFXmjn7V4Dck8qvQNjkIMXGZR REwtd9Q9furbQ/lFRj5OwWloKfUfBZha3MAv3mIHi9hqGDGtE39N5jDl65KI0RnZbzoR dVlGeJDBS+95Uk46kOooR+xsbvuirOTi82nrpbIqSZfnCz0dsHmuyrqZeKOknFZTailm /01g== X-Gm-Message-State: AOJu0Yy5hRlbg4yRnbv6tM1Um9pgOK7C+ynGMuyB/CIlp2k1w5zuVK5X SOxiysoIf+/yi9DJPNdPTz7qM1XeixhZ5+9xiL/PBXHiYeUnl2GSefR5wEbBGEMJTWgUzxtkRF6 Z6OJXwOA8bUY= X-Received: by 2002:a05:6000:120f:b0:31f:ffe3:b957 with SMTP id e15-20020a056000120f00b0031fffe3b957mr1698502wrx.31.1695923481147; Thu, 28 Sep 2023 10:51:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYcuBaOu3jvw3GrSl/OuumCYTHTHQoVIIWotVFgz3Bzwq6L9eXfAvgxP8GhDuGA2gj4SKzuw== X-Received: by 2002:a05:6000:120f:b0:31f:ffe3:b957 with SMTP id e15-20020a056000120f00b0031fffe3b957mr1698482wrx.31.1695923480663; Thu, 28 Sep 2023 10:51:20 -0700 (PDT) Received: from ?IPV6:2003:cb:c718:f00:b37d:4253:cd0d:d213? (p200300cbc7180f00b37d4253cd0dd213.dip0.t-ipconnect.de. [2003:cb:c718:f00:b37d:4253:cd0d:d213]) by smtp.gmail.com with ESMTPSA id m26-20020a056000025a00b003233a31a467sm6288708wrz.34.2023.09.28.10.51.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Sep 2023 10:51:20 -0700 (PDT) Message-ID: <85e5390c-660c-ef9e-b415-00ee71bc5cbf@redhat.com> Date: Thu, 28 Sep 2023 19:51:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 To: 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, lokeshgidra@google.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> 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: 7bit X-Stat-Signature: 1n8wttcaoxqa3qkmtqfwqd98o68nt1bg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A9B97140022 X-Rspam-User: X-HE-Tag: 1695923485-260812 X-HE-Meta: U2FsdGVkX1/1xP81eGM6+0htSet1O7O5NZ4tIOJJFRcaU1NW1tNVM7O1Fb7a9okXl1CMUCem8lR+tfF6pAjv/monvqqfuiAbwKPrNTEMVWoPtaBdBS8ea9dd9J8k1WxUiHw8LhHS1GPpfR6EKInROfi7tGMdSsVRot8Z8yWjt9LtZREp0g0fYsr+F9lCbdd0BvxYtMOQtK89rH+hMDLwsWGEjIiEXsVuysEOsgOkwmBMdZh0EKmwRHO6Ggjiybui3obU3awTdWMl0ype/JVYNrNBvGcjyLEoRcwjuCbUKs5EU+RA5QgaNA50WQRTHs8f94+s/scXVaiq6pygIPns/skmb2dYIj61HP3mmNkMgJTYkgkbxwwmDyiHBSKA9Uyv6ZbqUxYu4m2LLMfqyfrZMYVQxuFgys5GI/+KhE0SlnhKOYWp9Xc4gVFljv01usedlTV4BLJDx9hqPW0MkH04pDnTcls3c6XoUoRxeiSQlKKRv+wU4Qa4/4MAtcZbYk502ygqaWzwS9mFP+q1Hp0IRhmPIVCI8uggZhOmv9EH9OnUm6jjyN3EwGpDbs5z8fgRvE2QvAAqAbIqmimemV+MRJ0N0itjxONPQVsSqPSedF87mPnFEgxqKz43FE9DQzirGPOEEGydjYle6B0RUfMUEq3fYYiOsoBKNxg0IBMH3idNBv5jL2RvOnGAVBn6QH8zV/aLrZYXuvvu3aRE0izhTykKIr4DtK+pczflGJ6X2DIpowUPhB6TOpIjRkxQpRkZDpEN/2dyLnf1dE8m46mcMmABusy6zfI97/jFIxmBXbXh0ulHNp3vLvsXn+aNlTZaCx1H38wd+Cx3dbHw2XFwCfv3wMae9p5Bq7qzNw0M0ExS5pdX2WqE+WoLULL/4cUrGUhqqCthiqeyhRh670U3iUsSl55jI+3GW5ULbqo4/Wr8Q0mlp1WkhpVtM4e/Z/LX0RJ0Tzav9fiC4Wxnda1 1cKof2dc HNGhxMldWWxuR8VISHSllWzCr/qoGpAm94AVSA8CTgqvZI33zLwOa4eFFvJKU7oO7XdE0BlxmJ8Ef9T/+Sa71x71YOBRt2ozKPPDXTXyreeRFsad1E+5x9cZrfvWmeARQyiGcR/Hv3M+fORHyXj43UrrbVt1W3Fef+BV7EfHMZgSJwjHmXPUZG+24mtwo8+RLDPtziwJmt1poOUnXS14EK9oFTCgP6wnNnrP+o9pX4flbI5wFmrwZmYoDLxabi6FY7tntXavQsyiLGGwfr8BIsafE5/m7m5Of78IADEmayi4rKYfBOW5j8Pb2HCiX3/WGmqM0VGMrHfmNFVqe6zuFGDJFufJlWQMW336Tfjn3ImVID6x+TACU9qQpN0oOD5LHO5TY5/a3IzMian7fifhNbeccwvdootfTQ6DopWEir2OgnYJ05DU1yOwPzg== 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 28.09.23 19:21, Peter Xu wrote: > On Thu, Sep 28, 2023 at 07:05:40PM +0200, David Hildenbrand wrote: >> As described as reply to v1, without fork() and KSM, the PAE bit should >> stick around. If that's not the case, we should investigate why. >> >> If we ever support the post-fork case (which the comment above remap_pages() >> excludes) we'll need good motivation why we'd want to make this >> overly-complicated feature even more complicated. > > The problem is DONTFORK is only a suggestion, but not yet restricted. If > someone reaches on top of some !PAE page on src it'll never gonna proceed > and keep failing, iiuc. Yes. It won't work if you fork() and not use DONTFORK on the src VMA. We should document that as a limitation. For example, you could return an error to the user that can just call UFFDIO_COPY. (or to the UFFDIO_COPY from inside uffd code, but that's probably ugly as well). > > do_wp_page() doesn't have that issue of accuracy only because one round of > CoW will just allocate a new page with PAE set guaranteed, which is pretty > much self-heal and unnoticed. Yes. But it might have to copy, at which point the whole optimization of remap is gone :) > > So it'll be great if we can have similar self-heal way for PAE. If not, I > think it's still fine we just always fail on !PAE src pages, but then maybe > we should let the user know what's wrong, e.g., the user can just forgot to > apply DONTFORK then forked. And then the user hits error and don't know > what happened. Probably at least we should document it well in man pages. > Yes, exactly. > Another option can be we keep using folio_mapcount() for pte, and another > helper (perhaps: _nr_pages_mapped==COMPOUND_MAPPED && _entire_mapcount==1) > for thp. But I know that's not ideal either. As long as we only set the pte writable if PAE is set, we're good from a CVE perspective. The other part is just simplicity of avoiding all these mapcount+swapcount games where possible. (one day folio_mapcount() might be faster -- I'm still working on that patch in the bigger picture of handling PTE-mapped THP better) -- Cheers, David / dhildenb