Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3032166rdh; Wed, 27 Sep 2023 23:45:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyw/zH6etb0DSA9yCBSU1aD5pOnlgCDJZEKhmQn/kru5XbRjg3mOO6srTXvxkMOURJC4W4 X-Received: by 2002:a17:902:d303:b0:1c1:eb8b:79a6 with SMTP id b3-20020a170902d30300b001c1eb8b79a6mr319782plc.24.1695883548337; Wed, 27 Sep 2023 23:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695883548; cv=none; d=google.com; s=arc-20160816; b=zKeHYv7mY5U9Rstyq6xOmsN9LhsvEPZBwj2wmp8iQSqyvK6j7Ep5MyTBVrPjQbOSxK 0jhR/VhEKykLsK9UdAmAsHqC2ieqG/RuojTFZipu+Vwn/e1A5hMGCZmgqCCeL3PKYRRm Nb6cEnGRG1CHWSBOKorowjUfjF9F+hh6WWn3w7CBehNIUXmoVGPwBB31r7iUxFsOlv+v oXJtxvPCU/GS/VKATgyEsVsWISCbzL7pM7FApZJZ/BFOIRYxnFAm2ysw76RFDHC35YC9 OehVkv6+c9t1nk5zCPPtJY4b7DHeVcJ9edNlfyifYVJZjtRyWi5wQ9CyYM35fKN2AuJu mn0A== 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=XIJKJLaNcL8GDk+Ht7dCkCTcNn0oTRzFCuMLCDfzqz0=; fh=Mn5HfQMW1eim3i3AcQEmY+4uDleqNksYHlEpogfGoIA=; b=Fsn+mUijECiMJu5YJcWa78CoU1zRWEa7/m0AYWPHWZsoRK1eLb72OsHDnDw4NTAHtR dwzmUSNkULNQ9kukl2jO72MmODAxcdWsQ3YrCrndYj8/zj5Vo8E9VYW+UYmJmhGkltxD pUisr/t40Cwp7wnZ44w6JbxYKKsBMKtj45XvvCo20vjUp2pdZ6IE7YxPlnYriVq3Mpfd tgMZM4UhqGfmNqUWnTVgZ06lflmwCbS1zOWEBwqUentGO6zQnYChnFllTqccUL4EQwlZ t1UuazROsJhIX/NEFOU7pWw3AwyJX7KBb7tlqrv8OEdPbHfmSoVZMK2J+EADBdbk2C+7 N5Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AaSwqqVe; 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 p6-20020a170902780600b001bdc664cd69si16937753pll.153.2023.09.27.23.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 23:45:48 -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=AaSwqqVe; 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 E66AA828012C; Wed, 27 Sep 2023 15:49:30 -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 S229959AbjI0WtW (ORCPT + 99 others); Wed, 27 Sep 2023 18:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbjI0WtV (ORCPT ); Wed, 27 Sep 2023 18:49:21 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A071B1 for ; Wed, 27 Sep 2023 15:49:15 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c6193d6bb4so75985ad.0 for ; Wed, 27 Sep 2023 15:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695854955; x=1696459755; 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=XIJKJLaNcL8GDk+Ht7dCkCTcNn0oTRzFCuMLCDfzqz0=; b=AaSwqqVeTdv/v3H+H80PAcofpbSf4vm8a0iBx5kRp/QN8d5Q7k4kEMAwranTVwK5DI zxl0b+yUVWrp0Bfvlh94o6xMQohl7MzeA82Jf1T4ZnXrId3OwMnWUSOv81jl/yDlNN6N ZMZuQ5pA6WIGvyZBa+lsdo3b22ubzzpFXw1tL7kF821Ych4NmYLEtRXfXat12nJO9IIN 8l3as0d5Vmxdy1O4+XMmZg4ivZ4hoq922Q7UVY363liccm1ZO8yIfjh1PTvOWgfrohHx jecj7jeBZcIFrywKs5pFQeQwFqnYXCe+vO6ZwSn2zFptJ6C1BHyAeY2bb7lNtHrasfpr 2oVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695854955; x=1696459755; 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=XIJKJLaNcL8GDk+Ht7dCkCTcNn0oTRzFCuMLCDfzqz0=; b=I04a+pyqgpeaycaEt7IkdWmaFCXVrTtNf7cKguXegHNZ+wT7sI6wgQbcIYLM9m+gdh Wk/TF8I8nbpJzrWeEO51cx4rP+DIvigNrMv0nUOJdf1c54f+Au10uOc+0FB3W7eV8xui WF51/06zaHLmJBx+V5KsUlnN1/xG6JuupCLsdNZgi4iu4Yr79TyzsKqcb9Rt73G2IjJp aFSZMd6LK3pH6+UDVkY474DhUIGX4IfBMNyWa6oCOX1e+yKLk9vwgdpSXj2dFqjlkbUG i0bbKCxWHiPrkqVFfiztqgjuBlVDht7DQqC1Zh72KtEVcZIi+T7s6lqygfug1rL0UAnZ +AZg== X-Gm-Message-State: AOJu0Yw0yGlGIM+nCORPL/Wf9tm+nUeVwOYTMVHHh/tvvBYts62ygKNe YmvJ3RrAy4AX8/NMWVDxbEkiF/0tQ3T+X0nD4C+2Fw== X-Received: by 2002:a17:902:e751:b0:1c6:112f:5ceb with SMTP id p17-20020a170902e75100b001c6112f5cebmr562761plf.25.1695854955102; Wed, 27 Sep 2023 15:49:15 -0700 (PDT) MIME-Version: 1.0 References: <20230923013148.1390521-1-surenb@google.com> <20230923013148.1390521-3-surenb@google.com> In-Reply-To: From: Jann Horn Date: Thu, 28 Sep 2023 00:48:37 +0200 Message-ID: Subject: Re: [PATCH v2 2/3] userfaultfd: UFFDIO_REMAP uABI To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, peterx@redhat.com, david@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 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]); Wed, 27 Sep 2023 15:49:31 -0700 (PDT) On Wed, Sep 27, 2023 at 11:08=E2=80=AFPM Suren Baghdasaryan wrote: > On Wed, Sep 27, 2023 at 1:42=E2=80=AFPM Suren Baghdasaryan wrote: > > > > On Wed, Sep 27, 2023 at 1:04=E2=80=AFPM Jann Horn wr= ote: > > > > > > On Wed, Sep 27, 2023 at 8:08=E2=80=AFPM Suren Baghdasaryan wrote: > > > > On Wed, Sep 27, 2023 at 5:47=E2=80=AFAM Jann Horn wrote: > > > > > On Sat, Sep 23, 2023 at 3:31=E2=80=AFAM Suren Baghdasaryan wrote: > > > > > > + dst_pmdval =3D pmdp_get_lockless(dst_pmd); > > > > > > + /* > > > > > > + * If the dst_pmd is mapped as THP don't overri= de it and just > > > > > > + * be strict. If dst_pmd changes into TPH after= this check, the > > > > > > + * remap_pages_huge_pmd() will detect the chang= e and retry > > > > > > + * while remap_pages_pte() will detect the chan= ge and fail. > > > > > > + */ > > > > > > + if (unlikely(pmd_trans_huge(dst_pmdval))) { > > > > > > + err =3D -EEXIST; > > > > > > + break; > > > > > > + } > > > > > > + > > > > > > + ptl =3D pmd_trans_huge_lock(src_pmd, src_vma); > > > > > > + if (ptl && !pmd_trans_huge(*src_pmd)) { > > > > > > + spin_unlock(ptl); > > > > > > + ptl =3D NULL; > > > > > > + } > > > > > > > > > > This still looks wrong - we do still have to split_huge_pmd() > > > > > somewhere so that remap_pages_pte() works. > > > > > > > > Hmm, I guess this extra check is not even needed... > > > > > > Hm, and instead we'd bail at the pte_offset_map_nolock() in > > > remap_pages_pte()? I guess that's unusual but works... > > > > Yes, that's what I was thinking but I agree, that seems fragile. Maybe > > just bail out early if (ptl && !pmd_trans_huge())? > > No, actually we can still handle is_swap_pmd() case by splitting it > and remapping the individual ptes. So, I can bail out only in case of > pmd_devmap(). FWIW I only learned today that "real" swap PMDs don't actually exist - only migration entries, which are encoded as swap PMDs, exist. You can see that when you look through the cases that something like __split_huge_pmd() or zap_pmd_range() actually handles. So I think if you wanted to handle all the PMD types properly here without splitting, you could do that without _too_ much extra code. But idk if it's worth it.