Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3592138rdh; Thu, 28 Sep 2023 17:13:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWCwvUuqambWVySDyaC26PB6ajitq6Q9bupyAbbjve5Ao5MeW5Dt9znq9+inPtCx9sbwsT X-Received: by 2002:a05:6871:88e:b0:1bb:b13c:7fa4 with SMTP id r14-20020a056871088e00b001bbb13c7fa4mr3199701oaq.26.1695946419732; Thu, 28 Sep 2023 17:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695946419; cv=none; d=google.com; s=arc-20160816; b=V8/2O9g6wRDu5F6iSmOX4JC+RQhFFQHFIlZ3Glnh3No0KXDrX5HHi/fwrWkzat9Yxc UDYiMmyr9nM80k+URtfwLpDpIjSIGxhhsRTvN7fqRFc5ajgNj3Tc2Co6nIK8VNFllI+k SOJKHlKLkRJ5Ax5Ldy8QhiP3k34j7K/8Lw6W5TtOeH3q1sGvdYF84X36rAbYW12Tld5x F5yBn5K9iTfgMu54UtdSYyQSazf34o+l/C52C+i4LAgBQfOcUsAVcoP9MrhGU8ZGORHE d3TBscJsBuSa86LJaUxyoUwrdF9FEJRm9YTCZIVZ/NxUD2iEuDGl5nRhs4ovYDfZgNOd n8GA== 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=mlqQYHcSZTQEN/TIyJgTq3z/gFgEQXlRPAw0wk0he68=; fh=W4+pEOKWCNW9BFxJSKlAkzIU4JLOzdQkFOwEYjNGfBg=; b=qmjwWj4oi59QsLJ8SR9txpElnzRNFuiYobNm6PZBLAIlzB77aHgCjzH2ZEP+/vtfTn aQ/l8B/toQn05pPWtehwoulDYxapaMdy+zG8NjndL1HPvgswyzkc93rS1TpAWHvoWWyU KPjZUe8xQ8typF5JpO5pp7j7D5K6PnYbRv/IKk5+gC47Y+FLhyUWdJf1S34ROcNmeLJD 5HFM1BzmXkC7wAAmmrGMuyUnOOJTuBMFuA+W4waD9WhW9zdaYzIqPex+mz7xkVtDY0eK Ewc8yI1rGBajCRW39EGkz8djT2SgAmoSi5A7jT7BRh7uf48LFSpgncGN9A5Ng7pFzrji m3Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GWddrRrb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id m1-20020a656a01000000b00578b4082453si22652954pgu.712.2023.09.28.17.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 17:13:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GWddrRrb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 44B42801FA11; Thu, 28 Sep 2023 12:47:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232052AbjI1Trj (ORCPT + 99 others); Thu, 28 Sep 2023 15:47:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjI1Trh (ORCPT ); Thu, 28 Sep 2023 15:47:37 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A2541A3 for ; Thu, 28 Sep 2023 12:47:35 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-579de633419so164060707b3.3 for ; Thu, 28 Sep 2023 12:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695930454; x=1696535254; 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=mlqQYHcSZTQEN/TIyJgTq3z/gFgEQXlRPAw0wk0he68=; b=GWddrRrbnYUphjZdUbBst7J4k0tIbE91q6ZTHTt7wDfxvFZEoMblwQVourdFoZaXJZ XjSW8LR+YEiRq2NWST+DwWlC7jPDlL6X5UIvqWaXq0qWHwR/Kc0Ei2WChLxOgdqXw0Vt PGkZO6Qin3sFGK3ymXMGWvKhnUTxSYdJokhLEpR75ooakrLPr/5QDDiJwhjZoK0G9gCH PJc2bizWZtS873A3V2SDk4kxazsIpgu7kK69vu5Ze6FyKXHvdcng9DjJyYAO43fCwPHe 7KfvPjGfa88GIVabBC81yHxL9XJpIs+9RGiiLyGWOSujF4QDvwrs/m8Ur3GfQnsdWwCl SvAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695930454; x=1696535254; 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=mlqQYHcSZTQEN/TIyJgTq3z/gFgEQXlRPAw0wk0he68=; b=pWpc/jaEsL1BW0GZ7McGNrqmE4bu5Fpe6RRzGUNB3R8Mrt5FJpAlIYlOljpmcl1nWM xy00AG7URJoQCuqfWsi4+dYz1iHlCHmtrFIZtBqxm/aWn+8VsmFi6JD7/1zMBhl4ZnT/ fNhN+puCDAz5wffnGpO4sZwZ7d/5S+U8zH1/eaLrTKNnhgxLcVmMdo+LmFvyJXCc5RCX Y2tHmBIkvas1mKxLISqBP61M5G/9C1Pogdv9VU2boJ/Jnma/glWUORC3816x01lPyq9I WsxZaO10RoraiqbFwpkVkCQTqHKfoXDRuORojBIFAmVP1mFYo8i1vWveuhluEYOg+Vza 3sTg== X-Gm-Message-State: AOJu0YxwXQhdLIQOEs54oIIEcQ5D0RllnraQI71+5uukqwdSjO3p5KSZ pRa6011doZEXkxALUM9BGQQB/+qFalGv/c60hyuYJQ== X-Received: by 2002:a0d:df45:0:b0:59f:6175:bd72 with SMTP id i66-20020a0ddf45000000b0059f6175bd72mr2137442ywe.6.1695930454372; Thu, 28 Sep 2023 12:47:34 -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> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 28 Sep 2023 12:47:21 -0700 Message-ID: Subject: Re: [PATCH v2 2/3] userfaultfd: UFFDIO_REMAP uABI To: Peter Xu Cc: David Hildenbrand , Jann Horn , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 12:47:55 -0700 (PDT) On Thu, Sep 28, 2023 at 11:34=E2=80=AFAM Peter Xu wrote= : > > On Thu, Sep 28, 2023 at 07:51:18PM +0200, David Hildenbrand wrote: > > 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 sh= ould > > > > stick around. If that's not the case, we should investigate why. > > > > > > > > If we ever support the post-fork case (which the comment above rema= p_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 pro= ceed > > > and keep failing, iiuc. > > > > Yes. It won't work if you fork() and not use DONTFORK on the src VMA. W= e > > 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). > > We could indeed provide some special errno perhaps upon the PAE check, th= en > document it explicitly in the man page and suggest resolutions (like > DONTFORK) when user hit it. > > > > > > > > > do_wp_page() doesn't have that issue of accuracy only because one rou= nd of > > > CoW will just allocate a new page with PAE set guaranteed, which is p= retty > > > much self-heal and unnoticed. > > > > Yes. But it might have to copy, at which point the whole optimization o= f > > remap is gone :) > > Right, but that's fine IMHO because it should still be very corner case, > definitely not expected to be the majority to start impact the performanc= e > results. > > > > > > > > > So it'll be great if we can have similar self-heal way for PAE. If n= ot, 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 for= got to > > > apply DONTFORK then forked. And then the user hits error and don't k= now > > > what happened. Probably at least we should document it well in man p= ages. > > > > > Yes, exactly. > > > > > Another option can be we keep using folio_mapcount() for pte, and ano= ther > > > helper (perhaps: _nr_pages_mapped=3D=3DCOMPOUND_MAPPED && _entire_map= count=3D=3D1) > > > 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) > > Sure. > > For now as long as we're crystal clear on the possibility of inaccuracy o= f > PAE, it never hits besides fork() && !DONTFORK, and properly document it, > then sounds good here. Ok, sounds like we have a consensus. I'll prepare manpage changes to document the DONTFORK requirement for uffd_remap. > > Thanks, > > -- > Peter Xu >